After switching from Tomcat 5.5 to Tomcat 6.0.24, every now and then Tomcat's WebappClassLoader throws StringIndexOutOfBoundsExceptions, which leads to various exceptions like NoDefClassFoundError. With Tomcat 5.5, everything went fine. The web application in which the exceptions occur remained untouched throughout the whole time. The error is also present in Tomcat 6.0.26. Here is a short stack trace from the Catalina log file: java.lang.StringIndexOutOfBoundsException: String index out of range: 95 at java.lang.String.substring(String.java:1934) at org.apache.catalina.util.RequestUtil.normalize(RequestUtil.java:131) at org.apache.naming.resources.FileDirContext.normalize(FileDirContext.java:771) at org.apache.naming.resources.FileDirContext.file(FileDirContext.java:809) at org.apache.naming.resources.FileDirContext.getAttributes(FileDirContext.java:429) at org.apache.naming.resources.BaseDirContext.getAttributes(BaseDirContext.java:747) at org.apache.naming.resources.ProxyDirContext.getAttributes(ProxyDirContext.java:840) at org.apache.catalina.loader.WebappClassLoader.findResourceInternal(WebappClassLoader.java:2414) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2266) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:976) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1451) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1329) at java.lang.Class.getDeclaredClasses0(Native Method) at java.lang.Class.getDeclaredClasses(Class.java:1699)
I may note that the exception occurs after tomcat start up has finished.
It is very strange. The code in RequestUtil.normalize() is 126 // Resolve occurrences of "//" in the normalized path 127 while (true) { 128 int index = normalized.indexOf("//"); 129 if (index < 0) 130 break; 131 normalized = normalized.substring(0, index) + 132 normalized.substring(index + 1); 133 } I do not see how it can break. 1. What exact version of Java are you using? Is it 32-bit, or 64-bit? 2. What exact version of Tomcat 5.5.x were you using before? 3. Is this error reproducible, or it happens randomly? 4. Do you have any clue about what class it tried to load? Note, that it is possible to turn on debug logging in WebappClassLoader class, by adding the following line to conf/logging.properties: org.apache.catalina.loader.WebappClassLoader.level=FINE The code that fails is triggered only if the class file path contains a '//'. Having a double slash there is unusual. So maybe it is not Tomcat version change that triggers this, but how you web application is deployed. By the way, Tomcat 6.0.27 is already available for testing. See a [VOTE] thread on dev@ list.
I've looked at this and this is looking very much like a JVM bug but even then I can't see how it is being triggered.
See thread "Webapp reloading issue and intermittent 404 errors" on users@. http://markmail.org/message/xsrc4ek3bhkhsxi4 http://marc.info/?t=127773158900004&w=2