Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit aa3a94e

Browse files
Be sure to clear exceptions after a failed JNI lookup (#44293)
In the case that methods don't exist because we are running on an old Android SDK, clear the exception that the failed JNI lookup threw.
1 parent e8710ac commit aa3a94e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

shell/platform/android/platform_view_android_jni_impl.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,9 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
11851185
return false;
11861186
}
11871187

1188+
// Ensure we don't have any pending exceptions.
1189+
FML_CHECK(fml::jni::CheckException(env));
1190+
11881191
g_image_get_hardware_buffer_method =
11891192
env->GetMethodID(g_image_class->obj(), "getHardwareBuffer",
11901193
"()Landroid/hardware/HardwareBuffer;");
@@ -1193,6 +1196,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
11931196
FML_LOG(WARNING) << "Could not locate getHardwareBuffer on "
11941197
"android.media.Image";
11951198
// Continue on as this method may not exist at API <= 29.
1199+
fml::jni::ClearException(env);
11961200
}
11971201

11981202
g_image_close_method = env->GetMethodID(g_image_class->obj(), "close", "()V");
@@ -1202,6 +1206,8 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
12021206
return false;
12031207
}
12041208

1209+
// Ensure we don't have any pending exceptions.
1210+
FML_CHECK(fml::jni::CheckException(env));
12051211
g_hardware_buffer_class = new fml::jni::ScopedJavaGlobalRef<jclass>(
12061212
env, env->FindClass("android/hardware/HardwareBuffer"));
12071213

@@ -1212,6 +1218,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
12121218
FML_LOG(WARNING)
12131219
<< "Could not locate android.hardware.HardwareBuffer class";
12141220
// Continue on as this class may not exist at API <= 26.
1221+
fml::jni::ClearException(env);
12151222
}
12161223

12171224
g_compute_platform_resolved_locale_method = env->GetMethodID(

0 commit comments

Comments
 (0)