tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DO NOT REPLY [Bug 45442] New: Thread.currentThread.getClassLoader() wrong when looking up Resources
Date Sun, 20 Jul 2008 22:27:19 GMT

           Summary: Thread.currentThread.getClassLoader() wrong when looking
                    up Resources
           Product: Tomcat 6
           Version: unspecified
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina

I am using jboss 4.2.2 which as tomcat 6 embedded in it.

In tomcat you can specify a Resources class in context.xml. 'Resources' is used
to lookup resources (html, css, etc.). (more info on Resources at

Normally when your Resources class is called to lookup resourecs the thread's
classloader (Thread.currentThread.getClassLoader()) is set to the classloader
of the webapp as expected. Early on in a httpservletrequest tomcat runs through
some rules that are in the method internalMapWrapper of
org.apache.tomcat.util.http.mapper.Mapper (eg. looks to see if its a
welcomefile request, requesting a directory, etc.). When these rules are ran
the thread's classloader is NOT set to the webapp's classloader.

This inconsistency in the thread's classloader when running "Resources" can
should be fixed.

For me this caused random 404 responses. I received "random" 404 responses
because lookup calls to Resources class are cached by ProxyDirContxt.
ProxyDirContext wraps your "Resourcse" class. My Resources uses classes from
the webapps classloader.  Because of the inconsistency in the classloader my
Resources would sometimes say the resource doesn't exist, and in other does
exist -- depending no where the lookup takes place. The result of the lookup
would then be cached for something like 500ms.

As a temporarly solution i have overrode isCached() to always return false.
This causes ProxyDirContext to never cache the results.

When Resources lookup is done by
Thread.currentThread.getClassLoader() should return the classloader of the


Configure bugmail:
------- You are receiving this mail because: -------
You are the assignee for the bug.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message