From a9650709e3de5f7d8e698499c872745ffecd9093 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 3 May 2019 11:56:59 -0700 Subject: [PATCH] Fix multiple invocations of getConstants Summary: `jclass` in `JNI` is just a regular local reference. Therefore, it's unsafe to keep a static reference to it. Link: http://journals.ecs.soton.ac.uk/java/tutorial/native1.1/implementing/refs.html. This bug made it so that when you clicked on `getConstants` twice in the TurboModule playground, the app would crash. Reviewed By: mdvacca Differential Revision: D15174821 fbshipit-source-id: 13b2b8726473acc9b07306558044d26bed0db92d --- .../turbomodule/core/platform/android/JavaTurboModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp index d30a93c547b..77338d0aae1 100644 --- a/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp +++ b/ReactCommon/turbomodule/core/platform/android/JavaTurboModule.cpp @@ -109,7 +109,7 @@ jsi::Value convertFromJMapToValue(JNIEnv *env, jsi::Runtime &rt, jobject arg) { // This could also be done purely in C++, but iterative over map methods // but those may end up calling reflection methods anyway // TODO (axe) Investigate the best way to convert Java Map to Value - static jclass jArguments = env->FindClass("com/facebook/react/bridge/Arguments"); + jclass jArguments = env->FindClass("com/facebook/react/bridge/Arguments"); static jmethodID jMakeNativeMap = env->GetStaticMethodID(jArguments, "makeNativeMap", "(Ljava/util/Map;)Lcom/facebook/react/bridge/WritableNativeMap;"); auto constants = (jobject) env->CallStaticObjectMethod(jArguments, jMakeNativeMap, arg); auto jResult = jni::adopt_local(constants);