You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/11/16 23:04:43 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/loader AdaptiveClassLoader.java
craigmcc 00/11/16 14:04:42
Modified: src/share/org/apache/tomcat/loader Tag: tomcat_32
AdaptiveClassLoader.java
Log:
Make getResource() and getResourceAsStream() consult the parent class
loader (if there is one) before delegating to the system class loader.
This more accurately reflects the behavior of Java2 (JDK 1.2 and up) class
loader delegation.
PR: BugRat Bug Report #395
Submitted by: Rickard Oberg <ri...@telkel.com>
Revision Changes Path
No revision
No revision
1.9.2.2 +21 -5 jakarta-tomcat/src/share/org/apache/tomcat/loader/Attic/AdaptiveClassLoader.java
Index: AdaptiveClassLoader.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/loader/Attic/AdaptiveClassLoader.java,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -u -r1.9.2.1 -r1.9.2.2
--- AdaptiveClassLoader.java 2000/07/29 18:20:53 1.9.2.1
+++ AdaptiveClassLoader.java 2000/11/16 22:04:42 1.9.2.2
@@ -118,7 +118,7 @@
* @author Martin Pool
* @author Jim Heintz
* @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version $Revision: 1.9.2.1 $ $Date: 2000/07/29 18:20:53 $
+ * @version $Revision: 1.9.2.2 $ $Date: 2000/11/16 22:04:42 $
* @see java.lang.ClassLoader
*/
public class AdaptiveClassLoader extends ClassLoader {
@@ -661,8 +661,17 @@
public InputStream getResourceAsStream(String name) {
// Try to load it from the system class
if( debug > 0 ) log( "getResourceAsStream() " + name );
- InputStream s = getSystemResourceAsStream(name);
+ // First ask the parent class loader to fetch it, if possible
+ InputStream s = null;
+ if (parent != null) {
+ s = parent.getResourceAsStream(name);
+ if (s != null)
+ return (s);
+ }
+ // Second ask the system class loader to fetch it from the classpath
+ s = getSystemResourceAsStream(name);
+ // Third, check our own repositories
if (s == null) {
// Try to find it from every repository
Enumeration repEnum = repository.elements();
@@ -755,8 +764,15 @@
*/
public URL getResource(String name) {
if( debug > 0 ) log( "getResource() " + name );
- // First ask the primordial class loader to fetch it from the classpath
- URL u = getSystemResource(name);
+ // First ask the parent class loader to fetch it, if possible
+ URL u = null;
+ if (parent != null) {
+ u = parent.getResource(name);
+ if (u != null)
+ return (u);
+ }
+ // Second ask the system class loader to fetch it from the classpath
+ u = getSystemResource(name);
if (u != null) {
return u;
}
@@ -765,7 +781,7 @@
return null;
}
- // We got here so we have to look for the resource in our list of repository elements
+ // Third, check our own repositories
Enumeration repEnum = repository.elements();
while (repEnum.hasMoreElements()) {
ClassRepository cp = (ClassRepository) repEnum.nextElement();