Improve exception detail with JNI_OnLoad issues
Change-Id: I83c679d0b282f8d9ceb717acf20dda3af2124c66
diff --git a/src/jni_internal.cc b/src/jni_internal.cc
index 7c19025..2673074 100644
--- a/src/jni_internal.cc
+++ b/src/jni_internal.cc
@@ -2870,7 +2870,8 @@
self->SetClassLoaderOverride(old_class_loader);
if (IsBadJniVersion(version)) {
- LOG(ERROR) << "Bad JNI version returned from JNI_OnLoad in \"" << path << "\": " << version;
+ StringAppendF(&detail, "Bad JNI version returned from JNI_OnLoad in \"%s\": %d",
+ path.c_str(), version);
// It's unwise to call dlclose() here, but we can mark it
// as bad and ensure that future load attempts will fail.
// We don't know how far JNI_OnLoad got, so there could
@@ -2878,10 +2879,9 @@
// newly-registered native method calls. We could try to
// unregister them, but that doesn't seem worthwhile.
result = false;
- } else {
- VLOG(jni) << "[Returned " << (result ? "successfully" : "failure")
- << " from JNI_OnLoad in \"" << path << "\"]";
}
+ VLOG(jni) << "[Returned " << (result ? "successfully" : "failure")
+ << " from JNI_OnLoad in \"" << path << "\"]";
}
library->SetResult(result);
diff --git a/src/native/java_lang_Runtime.cc b/src/native/java_lang_Runtime.cc
index 54ccddc..56a3a06 100644
--- a/src/native/java_lang_Runtime.cc
+++ b/src/native/java_lang_Runtime.cc
@@ -66,6 +66,8 @@
return NULL;
}
+ // Don't let a pending exception from JNI_OnLoad cause a CheckJNI issue with NewStringUTF.
+ env->ExceptionClear();
return env->NewStringUTF(detail.c_str());
}