From d391323129d5d1fd8def426a99bc9356d2ab7e78 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Tue, 24 Jan 2017 15:45:26 -0800 Subject: [PATCH] Use findClassStatic instead of findClassLocal Summary: We are saving the class reference in a static variable to should be using findClassStatic to ensure the reference is always valid. Reviewed By: mhorowitz Differential Revision: D4420352 fbshipit-source-id: 8c66c1b2213fe295334a9bdc4e1dd7e1a4285aae --- java/jni/YGJNI.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/java/jni/YGJNI.cpp b/java/jni/YGJNI.cpp index 05d1c20e..222ce3ff 100644 --- a/java/jni/YGJNI.cpp +++ b/java/jni/YGJNI.cpp @@ -75,7 +75,8 @@ static void YGPrint(YGNodeRef node) { static float YGJNIBaselineFunc(YGNodeRef node, float width, float height) { if (auto obj = YGNodeJobject(node)->lockLocal()) { - return findClassLocal("com/facebook/yoga/YogaNode")->getMethod("baseline")(obj, width, height); + static auto baselineFunc = findClassStatic("com/facebook/yoga/YogaNode")->getMethod("baseline"); + return baselineFunc(obj, width, height); } else { return height; } @@ -87,7 +88,7 @@ static YGSize YGJNIMeasureFunc(YGNodeRef node, float height, YGMeasureMode heightMode) { if (auto obj = YGNodeJobject(node)->lockLocal()) { - static auto measureFunc = findClassLocal("com/facebook/yoga/YogaNode") + static auto measureFunc = findClassStatic("com/facebook/yoga/YogaNode") ->getMethod("measure"); YGTransferLayoutDirection(node, obj); @@ -121,7 +122,7 @@ static int YGLog(YGLogLevel level, const char *format, va_list args) { char buffer[256]; int result = vsnprintf(buffer, sizeof(buffer), format, args); - static auto logFunc = findClassLocal("com/facebook/yoga/YogaLogger") + static auto logFunc = findClassStatic("com/facebook/yoga/YogaLogger") ->getMethod, jstring)>("log"); static auto logLevelFromInt =