Skip to content

Commit 396d75a

Browse files
committed
Fix GetPlatformAppByName() to actually check the result of jni_env->ExceptionCheck() and return NULL if an exception was thrown.
1 parent 4a34edd commit 396d75a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/src/app_android.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,13 @@ static jobject GetPlatformAppByName(JNIEnv* jni_env, const char* name) {
311311
name_string);
312312
jni_env->DeleteLocalRef(name_string);
313313
}
314-
jni_env->ExceptionCheck();
314+
if (jni_env->ExceptionCheck()) {
315+
// Explicitly set `platform_app` to `NULL` if an exception was thrown
316+
// because on KitKat (API 19) `CallStaticObjectMethod()` may return garbage
317+
// instead of `NULL` if an exception was thrown, and callers of this
318+
// function expect `NULL` to be returned if the app was not found.
319+
platform_app = NULL; // NOLINT
320+
}
315321
jni_env->ExceptionClear();
316322
return platform_app;
317323
}

0 commit comments

Comments
 (0)