Since update to Tomcat 8.0.29 we noticed problems in our Struts based application. Some actions in random moments returned 404 errors without any log. The same problem appeared in 8.0.30-33. We analyzed changes made between versions 8.0.28 and 8.0.29 and by adding them one by one we found that the problem is caused by org.apache.catalina.mapper.Mapper and new properties in Context: mapperContextRootRedirectEnabled and mapperDirectoryRedirectEnabled. mappingData.context.getMapper...RedirectEnabled() throws in some situations null pointer exception because mappingData.context in null. After changing code of Mapper.java in Tomcat 8.0.33 and recompiling we confirmed that changes:879c879,883 < if(mappingData.wrapper == null && noServletPath) { --- > if (mappingData.wrapper == null && noServletPath && mappingData.context == null){ > log.error("Kaboom: " + mappingData.toString()); > } else { > if(mappingData.wrapper == null && noServletPath && > mappingData.context.getMapperContextRootRedirectEnabled()) { 887a892 > } 1006c1011,1015 < if (file != null && file.isDirectory()) { --- > if (file != null && file.isDirectory() && mappingData.context == null){ > log.error("Kaboom: " + mappingData.toString()); > } else { > if (file != null && file.isDirectory() && > mappingData.context.getMapperDirectoryRedirectEnabled()) { 1017a1027 > } logs in catalina.out: 31-Mar-2016 10:23:28.633 SEVERE [ajp-nio-0.0.0.0-8009-exec-1] org.apache.catalina.mapper.Mapper.internalMapWrapper Kaboom: org.apache.catalina.mapper.MappingData@6443d97d 31-Mar-2016 10:24:40.946 SEVERE [ajp-nio-0.0.0.0-8009-exec-1] org.apache.catalina.mapper.Mapper.internalMapWrapper Kaboom: org.apache.catalina.mapper.MappingData@6443d97d 31-Mar-2016 10:25:26.272 SEVERE [ajp-nio-0.0.0.0-8009-exec-3] org.apache.catalina.mapper.Mapper.internalMapWrapper Kaboom: org.apache.catalina.mapper.MappingData@14a421a8 If there is anything that we can do to help you solve this problem please send us information how we can help.
Certainly this sort of occurrence is not going to be logged. Besides concurrent recycling, I don't really see what could cause it as mappingData.context is set right before calling internalMapWrapper, so it's really something that is up to you to debug. IMO this should be INVALID until you demonstrate some reasonably legitimate course of action that leads to the NPE.
1. Sample configuration / steps to reproduce the issue = ? 2. Diffs are preferred in Unified Diff format http://tomcat.apache.org/bugreport.html#How_to_submit_patches_and_enhancement_requests
Looking at 8.0.x Mapper.java, I think that in both mentioned places mappingData.context.getMapperContextRootRedirectEnabled() has be replaced with obtaining the context from ContextVersion object. Both places have it, so I see no reason why context is retrieved from mappingData. A test case is TBD.
Ok, so mappingData.context -> contextVersion.object. No problem. Since I don't see how mappingData.context becomes null, mappingData.wrapper probably also gets reset as well which will randomly mess up the mapping algorithm.
Ok, I applied this for 9M5, 8.5.1, 8.0.34.