--- old/src/hotspot/share/prims/jni.cpp 2017-10-04 10:10:57.000000000 -0700 +++ new/src/hotspot/share/prims/jni.cpp 2017-10-04 10:10:56.000000000 -0700 @@ -92,7 +92,7 @@ #include "jvmci/jvmciRuntime.hpp" #endif -static jint CurrentVersion = JNI_VERSION_9; +static jint CurrentVersion = JNI_VERSION_10; #ifdef _WIN32 extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* ); @@ -400,8 +400,8 @@ Handle protection_domain; // Find calling class Klass* k = thread->security_get_caller_class(0); + InstanceKlass* ik = NULL; if (k != NULL) { - loader = Handle(THREAD, k->class_loader()); // Special handling to make sure JNI_OnLoad and JNI_OnUnload are executed // in the correct class context. if (loader.is_null() && @@ -417,11 +417,17 @@ THROW_HANDLE_0(ex); } oop mirror = (oop) result.get_jobject(); - loader = Handle(THREAD, - InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->class_loader()); - protection_domain = Handle(THREAD, - InstanceKlass::cast(java_lang_Class::as_Klass(mirror))->protection_domain()); + if (mirror != NULL) { + ik = InstanceKlass::cast(java_lang_Class::as_Klass(mirror)); + protection_domain = Handle(THREAD, ik ->protection_domain()); + } + } else { + ik = InstanceKlass::cast(k); } + } + + if (ik != NULL) { + loader = Handle(THREAD, ik ->class_loader()); } else { // We call ClassLoader.getSystemClassLoader to obtain the system class loader. loader = Handle(THREAD, SystemDictionary::java_system_loader());