From 617bd85578b22de46b752864be940fe1e9187f1c Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 8 Apr 2014 15:54:22 -0600 Subject: [PATCH] initialize class in JNIEnv::FindClass Although the JNI reference documentation does not mention it, FindClass should initialize the class before it returns it. That's what HotSpot does, and that's what we have to do too. In particular, OpenJDK's Java_java_net_Inet6AddressImpl_lookupAllHostAddr relies on Inet6Address's static initializer being run when it is resolved using FindClass, or else it will crash. --- src/jnienv.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 6872d775f1..420feaec12 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -349,12 +349,16 @@ findClass(Thread* t, uintptr_t* arguments) object caller = getCaller(t, 0); - return reinterpret_cast - (makeLocalReference - (t, getJClass - (t, resolveClass - (t, caller ? classLoader(t, methodClass(t, caller)) - : root(t, Machine::AppLoader), n)))); + object c = resolveClass(t, + caller ? classLoader(t, methodClass(t, caller)) + : root(t, Machine::AppLoader), + n); + + PROTECT(t, c); + + initClass(t, c); + + return reinterpret_cast(makeLocalReference(t, getJClass(t, c))); } jclass JNICALL