tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aaron Hamid <ar...@cornell.edu>
Subject Subtlety in WebappClassLoader wrt to leading '/'
Date Wed, 09 Nov 2005 20:19:32 GMT
Hi all,

  I have searched bugzilla, and the tc-users and tc-dev lists on MARC, as well as the source
code, so hopefully this is vetted enough for this list (I have NOT posted a bug).

It appears that WebappClassLoader (in at least versions 5.0.28 and 5.5.12 which I have looked
at) will accept a leading slash '/' on the resource path parameter to the 'getResource*()'
calls.  This implicit support appears to be due to the File and URI/URL APIs it uses to resolve
the resource.

While it is intuitive to me to support a leading slash, Sun's application class loader behavior
is different.  Resource paths with leading slashes are not found.  When the slash is removed
they are found.  I could not find any mention of these semantics in the standard ClassLoader
(not Class, I am aware of how Class.getResource differs) documentation, however a quick Google
search will confirm the notion that ClassLoader will not find resources with leading slashes
(at least one old post on tomcat-dev: http://mail-archives.apache.org/mod_mbox/tomcat-dev/200108.mbox/%3C3B7854FF.2FA71171@apache.org%3E
quote at bottom).

I raise this issue because I just spent a lot of time debugging a problem where a certain
resource WAS found in Tomcat, but was not found when running JUnit tests from Ant or from
within Eclipse.  Ultimately it was my fault for prepending a slash, but I wonder if it is
worth either matching Sun's behavior, or documenting this somewhere (and again, I may have
missed it).

Aaron Hamid
CIT/ATA
Cornell University

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


Mime
View raw message