diff --git a/classpath/avian/SystemClassLoader.java b/classpath/avian/SystemClassLoader.java index abcf596bd5..2257a9b66e 100644 --- a/classpath/avian/SystemClassLoader.java +++ b/classpath/avian/SystemClassLoader.java @@ -33,6 +33,9 @@ public class SystemClassLoader extends ClassLoader { private native boolean resourceExists(String name); + private static native Class resolveClass(ClassLoader loader, byte[] spec) + throws ClassNotFoundException; + protected URL findResource(String name) { if (resourceExists(name)) { try { @@ -45,11 +48,18 @@ public class SystemClassLoader extends ClassLoader { private static Class loadClass(ClassLoader loader, byte[] nameBytes, int offset, int length) { - String name = new String(nameBytes, offset, length, false); + byte[] spec = new byte[length + 1]; + System.arraycopy(nameBytes, offset, spec, 0, length); + try { - return loader.loadClass(name); + Class c = resolveClass(loader, spec); + if (c == null) { + throw new NoClassDefFoundError(); + } + return c; } catch (ClassNotFoundException e) { - NoClassDefFoundError error = new NoClassDefFoundError(name); + NoClassDefFoundError error = new NoClassDefFoundError + (new String(nameBytes, offset, length, false)); error.initCause(e); throw error; } @@ -158,7 +168,7 @@ public class SystemClassLoader extends ClassLoader { private static void parseAnnotationTable(ClassLoader loader, Addendum addendum) { - if (addendum != null && addendum.annotationTable != null) { + if (addendum != null && addendum.annotationTable instanceof byte[]) { try { addendum.annotationTable = parseAnnotationTable (loader, addendum.pool, new ByteArrayInputStream diff --git a/src/builtin.cpp b/src/builtin.cpp index 560f8cc53e..03a4fb01f6 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -231,6 +231,16 @@ Avian_avian_SystemClassLoader_findClass return search(t, name, resolveSystemClass, true); } +extern "C" JNIEXPORT int64_t JNICALL +Avian_avian_SystemClassLoader_resolveClass +(Thread* t, object, uintptr_t* arguments) +{ + object loader = reinterpret_cast(arguments[0]); + object spec = reinterpret_cast(arguments[1]); + + return reinterpret_cast(resolveClass(t, loader, spec)); +} + extern "C" JNIEXPORT int64_t JNICALL Avian_avian_SystemClassLoader_resourceExists (Thread* t, object, uintptr_t* arguments)