From 16a8777fd23b9eabf69cf6e7dfe7580bf63d9100 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 26 Mar 2011 18:20:45 -0600 Subject: [PATCH] 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. --- classpath/avian/SystemClassLoader.java | 42 ++++++++++++++++++++++++++ classpath/java/lang/ClassLoader.java | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/classpath/avian/SystemClassLoader.java b/classpath/avian/SystemClassLoader.java index 6334f82916..defb9d490a 100644 --- a/classpath/avian/SystemClassLoader.java +++ b/classpath/avian/SystemClassLoader.java @@ -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 getResources(String name) throws IOException { + Collection urls = new ArrayList(5); + + ClassLoader parent = getParent(); + if (parent != null) { + for (Enumeration 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 findResources(String name) { Collection urls = new ArrayList(1); URL url = findResource(name); diff --git a/classpath/java/lang/ClassLoader.java b/classpath/java/lang/ClassLoader.java index b2ee0b7f75..e245e4c9f1 100644 --- a/classpath/java/lang/ClassLoader.java +++ b/classpath/java/lang/ClassLoader.java @@ -93,7 +93,7 @@ public abstract class ClassLoader { avian.Classes.link(c.vmClass, this); } - private ClassLoader getParent() { + public final ClassLoader getParent() { return parent; }