mirror of
https://github.com/corda/corda.git
synced 2025-01-07 13:38:47 +00:00
override getResource(s) in SystemClassLoader
OpenJDK's java.lang.ClassLoader.getResource makes use of sun.misc.Launcher to load bootstrap resources, which is not appropriate for the Avian build, so we override it to ensure we get the behavior we want.
This commit is contained in:
parent
6bd9ec3735
commit
16a8777fd2
@ -12,6 +12,7 @@ package avian;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.MalformedURLException;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
@ -46,6 +47,47 @@ public class SystemClassLoader extends ClassLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
// OpenJDK's java.lang.ClassLoader.getResource makes use of
|
||||
// sun.misc.Launcher to load bootstrap resources, which is not
|
||||
// appropriate for the Avian build, so we override it to ensure we
|
||||
// get the behavior we want. This implementation is the same as
|
||||
// that of Avian's java.lang.ClassLoader.getResource.
|
||||
public URL getResource(String path) {
|
||||
URL url = null;
|
||||
ClassLoader parent = getParent();
|
||||
if (parent != null) {
|
||||
url = parent.getResource(path);
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
url = findResource(path);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
// As above, we override this method to avoid inappropriate behavior
|
||||
// in OpenJDK's java.lang.ClassLoader.getResources.
|
||||
public Enumeration<URL> getResources(String name) throws IOException {
|
||||
Collection<URL> urls = new ArrayList<URL>(5);
|
||||
|
||||
ClassLoader parent = getParent();
|
||||
if (parent != null) {
|
||||
for (Enumeration<URL> e = parent.getResources(name);
|
||||
e.hasMoreElements();)
|
||||
{
|
||||
urls.add(e.nextElement());
|
||||
}
|
||||
}
|
||||
|
||||
URL url = findResource(name);
|
||||
if (url != null) {
|
||||
urls.add(url);
|
||||
}
|
||||
|
||||
return Collections.enumeration(urls);
|
||||
}
|
||||
|
||||
protected Enumeration<URL> findResources(String name) {
|
||||
Collection<URL> urls = new ArrayList(1);
|
||||
URL url = findResource(name);
|
||||
|
@ -93,7 +93,7 @@ public abstract class ClassLoader {
|
||||
avian.Classes.link(c.vmClass, this);
|
||||
}
|
||||
|
||||
private ClassLoader getParent() {
|
||||
public final ClassLoader getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user