Fix bugs with child-first behaviour.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@209244 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -32,6 +32,10 @@ import java.io.IOException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A ClassLoader which sees only the specified classes.
|
* A ClassLoader which sees only the specified classes.
|
||||||
|
* <p>
|
||||||
|
* Note that this classloader is not "industrial strength"; users
|
||||||
|
* looking for such a class may wish to look at the Tomcat sourcecode
|
||||||
|
* instead. In particular, this class may not be threadsafe.
|
||||||
*/
|
*/
|
||||||
public class PathableClassLoader extends URLClassLoader {
|
public class PathableClassLoader extends URLClassLoader {
|
||||||
|
|
||||||
@@ -174,9 +178,18 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.loadClass(name, resolve);
|
return super.loadClass(name, resolve);
|
||||||
} else {
|
} else {
|
||||||
// ok, implement child-first
|
// Implement child-first.
|
||||||
|
//
|
||||||
|
// It appears that the findClass method doesn't check whether the
|
||||||
|
// class has already been loaded. This seems odd to me, but without
|
||||||
|
// first checking via findLoadedClass we can get java.lang.LinkageError
|
||||||
|
// with message "duplicate class definition" which isn't good.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class clazz = super.findClass(name);
|
Class clazz = findLoadedClass(name);
|
||||||
|
if (clazz == null) {
|
||||||
|
clazz = super.findClass(name);
|
||||||
|
}
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
resolveClass(clazz);
|
resolveClass(clazz);
|
||||||
}
|
}
|
||||||
@@ -236,23 +249,32 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.getResources(name);
|
return super.getResources(name);
|
||||||
} else {
|
} else {
|
||||||
Enumeration local = super.findResources(name);
|
Enumeration localResources = super.findResources(name);
|
||||||
Enumeration parent = getParent().getResources(name);
|
ClassLoader parentLoader = getParent();
|
||||||
|
if (parentLoader == null) {
|
||||||
|
// There is no way, as far as I am aware, to call
|
||||||
|
// getResources on the bootclassloader. The Class
|
||||||
|
// class has methods getResource and getResourceAsStream
|
||||||
|
// but not getResources. So I guess we just assume there
|
||||||
|
// aren't any matches in the bootloader..
|
||||||
|
return localResources;
|
||||||
|
}
|
||||||
|
Enumeration parentResources = parentLoader.getResources(name);
|
||||||
|
|
||||||
if (!local.hasMoreElements()) {
|
if (!localResources.hasMoreElements()) {
|
||||||
return parent;
|
return parentResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parent.hasMoreElements()) {
|
if (!parentResources.hasMoreElements()) {
|
||||||
return local;
|
return localResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector v = new Vector();
|
Vector v = new Vector();
|
||||||
while (local.hasMoreElements()) {
|
while (localResources.hasMoreElements()) {
|
||||||
v.add(local.nextElement());
|
v.add(localResources.nextElement());
|
||||||
}
|
}
|
||||||
while (parent.hasMoreElements()) {
|
while (parentResources.hasMoreElements()) {
|
||||||
v.add(parent.nextElement());
|
v.add(parentResources.nextElement());
|
||||||
}
|
}
|
||||||
return v.elements();
|
return v.elements();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user