Bug 49488 - Infrequent StringIndexOutOfBoundsException in WebappClassLoader
Summary: Infrequent StringIndexOutOfBoundsException in WebappClassLoader
Status: RESOLVED WORKSFORME
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.24
Hardware: PC Windows Server 2003
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-22 07:24 UTC by bratapfel81
Modified: 2010-07-07 23:16 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bratapfel81 2010-06-22 07:24:50 UTC
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)
Comment 1 bratapfel81 2010-06-22 07:31:52 UTC
I may note that the exception occurs after tomcat start up has finished.
Comment 2 Konstantin Kolinko 2010-06-22 10:35:31 UTC
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.
Comment 3 Mark Thomas 2010-06-25 04:00:34 UTC
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.
Comment 4 Konstantin Kolinko 2010-07-07 23:16:49 UTC
See thread "Webapp reloading issue and intermittent 404 errors" on users@.

http://markmail.org/message/xsrc4ek3bhkhsxi4
http://marc.info/?t=127773158900004&w=2