tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bradley Neuberg <>
Subject [PATCH] Bug and Bugfix for NetworkClassLoader
Date Wed, 29 Dec 1999 22:07:05 GMT
getResource() is not implemented in
org.apache.tomcat.core.ServletClassLoader nor in
org.apache.tomcat.util.NetworkClassLoader.  If called on an instance of
ServletClassLoader or NetworkClassLoader then getResource() cascades up
to the superclass ClassLoader which returns the wrong resource.  It is
strange that getResource() is not implemented, as getResourceAsStream()
is implemented in NetworkClassLoader.  Here is the missing getResource()
method for org.apache.tomcat.util.NetworkClassLoader:

    /** @return The URL that can retrieve the requested resource
        if such a resource exists, otherwise returns null */
    public URL getResource(String name) {
      URL resource;
      // Algorithm:
      // 1. first check the system path for the resource
      // 2. next  check the  delegate/parent class loader for the
      // 3. then attempt to get the resource from the url set.

      // Lets check the system path for the resource.
      resource = getSystemResource(name);
      if(resource != null)
          return resource;

      // Lets check the parent/delegate class loader for the resource.
      if(parent != null) {
          resource = parent.getResource(name);
          if(resource != null)
              return resource;

      // Lets load it ourselves.
      for(Enumeration e = urlset.keys(); e.hasMoreElements();) {
        URL url = (URL) e.nextElement();
        URLResourceReader urr = (URLResourceReader) urlset.get(url);
        if(urr != null)
          return url;

      // nothing found
      return null;

View raw message