summaryrefslogtreecommitdiff
path: root/runtime/java_vm_ext.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/java_vm_ext.cc')
-rw-r--r--runtime/java_vm_ext.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc
index b93b8f2a97..f2e3353631 100644
--- a/runtime/java_vm_ext.cc
+++ b/runtime/java_vm_ext.cc
@@ -905,8 +905,20 @@ bool JavaVMExt::LoadNativeLibrary(JNIEnv* env,
EnsureFrontOfChain(SIGSEGV);
}
+ // Temporarily reset any pending exception around the call to
+ // SetClassLoaderOverride: SetClassLoaderOverride creates a new
+ // global reference, which is illegal while we have an
+ // exception pending.
+ jthrowable on_load_exception = env->ExceptionOccurred();
+ env->ExceptionClear();
+
+ // Restore the current class loader (which was overridden above) to the previous state.
self->SetClassLoaderOverride(old_class_loader.get());
+ if (on_load_exception != nullptr) {
+ env->Throw(on_load_exception);
+ }
+
if (version == JNI_ERR) {
StringAppendF(error_msg, "JNI_ERR returned from JNI_OnLoad in \"%s\"", path.c_str());
} else if (JavaVMExt::IsBadJniVersion(version)) {