You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2004/02/03 05:10:13 UTC

DO NOT REPLY [Bug 26622] New: - WebappClassLoader is inconsistent on delegation of resource loading

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26622>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26622

WebappClassLoader is inconsistent on delegation of resource loading

           Summary: WebappClassLoader is inconsistent on delegation of
                    resource loading
           Product: Tomcat 5
           Version: 5.0.18
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Catalina
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: craig.mcclanahan@sun.com


The servlet specification recommends (Section 9.7.2) that containers be
"implemented so that classes and resources packaged within the WAR are loaded in
preference to classes and resources residing in container-wide library JARs." 
Catalina implements this such that, when the "delegate" property is set to false
(which is the default), WebappClassLoader will look locally first for the
loadClass() and getResource() methods.  However, WebappClassLoader does *not*
override the getResources() method inherited from the URLClassLoader base class
-- so getResources() behaves as if the "delegate" property is always "true".

This causes problems for applications that have a resource defined in both the
parent and webapp class loaders.  From the descriptions of getResource() and
getResources() in the ClassLoader javadocs, and from the servlet spec statement
above, it is natural to expect that the first URL returned by getResources(),
for a given resource name, will be the one retrieved if you call getResource()
with that same resource name.  This assumption is satisfied if the "delegate"
property is set to "true", but is *not* satisfied when the "delegate" property
is set to "false".  This behavior is more problematic than it might otherwise
be, because "false" is the default setting.

The recommended solution is to override the getResources() method in
WebappClassLoader.  If "delegate" is set to "true", return the concatentation of
calling "getParent().getResources()" followed by the list of matching resources
in the webapp class loader.  If "delegate" is false, however, concatenation
order should be reversed.

Note that this problem exists in Tomcat 4.1 as well.  However, because that
version is primarily in maintenance mode now, I did not bother to submit a
separate bug report for it.

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org