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
This commit is contained in:
Ramanpreet Nara authored and Facebook Github Bot committed 2019-05-03 12:00:19 -07:00
1 parent c9006ce5fb
commit a9650709e3
1 file changed
+1 -1
@@ -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);