Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] WebAppClassLoader.getResource accepts leading slash

Hi,

This works on Jetty, but fails on Tomcat (and probably other containers):

getClass().getClassLoader().getResource("/path/to/resource.txt");

I got bitten by this issue today and wasted an couple of hours
identifying the issue and fixing it.

The ClassLoader.getResource Javadocs says: "The name of a resource is
a '/'-separated path name that identifies the resource." So I'd say
that using a leading slash isn't not according to spec, and it makes
your app non-portable.

Jetty's WebAppClassLoader.getResource documents:

     NOTE: this method provides a convenience of hacking off a leading /
     should one be present. This is non-standard and it is recommended
     to not rely on this behavior

Having been bitten several times before, I'm proposing that we remove
this "convenience" or that we disable it by default and provide a
system property / setter to re-enable it for this who rely on it and
don't want to fix their apps. (If that isn't acceptable, I could live
with the default being current behavior with a switch to turn it off.)

WDYT?

Eirik.


Back to the top