Make ClasspathClassLoader::getResource child first
This commit is contained in:
1 file changed
+16
@@ -13,6 +13,7 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -107,6 +108,21 @@ public class ClasspathClassLoader extends URLClassLoader {
|
||||
+ "] parent: " + getParent() + ']';
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getResource(String name) {
|
||||
// Override to make it child-first. This is the method used by
|
||||
// pmd-java's type resolution to fetch classes, instead of loadClass.
|
||||
Objects.requireNonNull(name);
|
||||
|
||||
URL url = findResource(name);
|
||||
if (url == null) {
|
||||
// note this will actually call back into findResource, but
|
||||
// we can't avoid this as the super call
|
||||
return super.getResource(name);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
|
||||
synchronized (getClassLoadingLock(name)) {
|
||||
|
||||
Reference in new issue
Block a user