Bug 1328115 - 3. Check for exceptions when finding Java class; r=snorp
authorJim Chen <nchen@mozilla.com>
Mon, 09 Jan 2017 14:10:24 -0500
changeset 328548 8f6416404aeac786f727c76d609e00bd4612bf1e
parent 328547 4ddd36462bdf680de40297acfac032b42fa50831
child 328549 52f8121f00650836089d6f309aee266c7b5f878d
push id85476
push usernchen@mozilla.com
push dateMon, 09 Jan 2017 19:10:41 +0000
treeherdermozilla-inbound@8f6416404aea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1328115
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1328115 - 3. Check for exceptions when finding Java class; r=snorp Be more careful when we try to find Java classes, so that any exceptions are not ignored and passed on to the caller, which is likely to result in a hard-to-diagnose Dalvik/ART crash.
widget/android/jni/Utils.cpp
--- a/widget/android/jni/Utils.cpp
+++ b/widget/android/jni/Utils.cpp
@@ -252,33 +252,34 @@ void SetNativeHandle(JNIEnv* env, jobjec
                       static_cast<jlong>(handle));
 }
 
 jclass GetClassRef(JNIEnv* aEnv, const char* aClassName)
 {
     // First try the default class loader.
     auto classRef = Class::LocalRef::Adopt(aEnv, aEnv->FindClass(aClassName));
 
-    if (!classRef && sClassLoader) {
+    if ((!classRef || aEnv->ExceptionCheck()) && sClassLoader) {
         // If the default class loader failed but we have an app class loader, try that.
         // Clear the pending exception from failed FindClass call above.
         aEnv->ExceptionClear();
         classRef = Class::LocalRef::Adopt(aEnv, jclass(
                 aEnv->CallObjectMethod(sClassLoader, sClassLoaderLoadClass,
                                        StringParam(aClassName, aEnv).Get())));
     }
 
-    if (classRef) {
+    if (classRef && !aEnv->ExceptionCheck()) {
         return classRef.Forget();
     }
 
     __android_log_print(
             ANDROID_LOG_ERROR, "Gecko",
-            ">>> FATAL JNI ERROR! FindClass(className=\"%s\") failed. "
-            "Did ProGuard optimize away something it shouldn't have?",
+            ">>> FATAL JNI ERROR! FindClass(\"%s\") failed. "
+            "Does the class require a newer API version? "
+            "Or did ProGuard optimize away something it shouldn't have?",
             aClassName);
     aEnv->ExceptionDescribe();
     MOZ_CRASH("Cannot find JNI class");
     return nullptr;
 }
 
 void DispatchToGeckoThread(UniquePtr<AbstractCall>&& aCall)
 {