summaryrefslogtreecommitdiff
path: root/runtime/java_vm_ext.cc
diff options
context:
space:
mode:
author Daniel Colascione <dancol@google.com> 2017-02-23 20:30:00 -0800
committer Daniel Colascione <dancol@google.com> 2017-04-07 16:51:34 -0700
commitd111f90a386f7bad1474189390fce7a8d1ff1ab5 (patch)
tree4f0c7e197f37f5a76d40cf18dc8a52c1baa8822c /runtime/java_vm_ext.cc
parentc48266eb44296fa086868b82d8a3c2b57ce186ae (diff)
Avoid JNI usage error when JNI_OnLoad throws
Test: included Change-Id: I534de714fad2cfb9b53d66da11ade0e5142cb819
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)) {