From 7a6478465d5a85bc406a71f366b016fa519c82b8 Mon Sep 17 00:00:00 2001 From: Emily Janzer Date: Wed, 2 Oct 2019 11:59:47 -0700 Subject: [PATCH] Throw pending JNI errors after Java method discovery in TM Summary: I was trying to debug an issue with a method signature mismatch last week, but was having trouble figuring out the problem because the error I was getting was unrelated - apparently JNI will sometimes swallow the error and just fail mysteriously later on. Ramanpreet showed me this macro that will throw any pending exceptions, so let's do that after we try to lookup the Java method in case it fails. Reviewed By: RSNara Differential Revision: D17680121 fbshipit-source-id: 1f23e49014f7cc1616e111386d440637e6a74677 --- .../turbomodule/core/platform/android/JavaTurboModule.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp index 2f931adc0d3..46c1183e655 100644 --- a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp +++ b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp @@ -446,6 +446,10 @@ jsi::Value JavaTurboModule::invokeJavaMethod( jmethodID methodID = env->GetMethodID(cls, methodName.c_str(), methodSignature.c_str()); + // If the method signature doesn't match, show a redbox here instead of + // crashing later. + FACEBOOK_JNI_THROW_PENDING_EXCEPTION(); + // TODO(T43933641): Refactor to remove this special-casing if (methodName == "getConstants") { auto constantsMap = (jobject)env->CallObjectMethod(instance, methodID);