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

Be sure to clear exceptions after a failed JNI lookup #44293

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,9 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
return false;
}

// Ensure we don't have any pending exceptions.
FML_CHECK(fml::jni::CheckException(env));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps capture the result outside the assertion and DCHECK the result instead of a release assertion? Don't want us to crash if there is a pending exception from a non-Flutter component.


g_image_get_hardware_buffer_method =
env->GetMethodID(g_image_class->obj(), "getHardwareBuffer",
"()Landroid/hardware/HardwareBuffer;");
Expand All @@ -1193,6 +1196,7 @@ bool PlatformViewAndroid::Register(JNIEnv* env) {
FML_LOG(WARNING) << "Could not locate getHardwareBuffer on "
"android.media.Image";
// Continue on as this method may not exist at API <= 29.
fml::jni::ClearException(env);
}

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

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

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

g_compute_platform_resolved_locale_method = env->GetMethodID(
Expand Down