diff --git a/java/com/facebook/csslayout/CSSNode.java b/java/com/facebook/csslayout/CSSNode.java index b928c212..6d5d61b3 100644 --- a/java/com/facebook/csslayout/CSSNode.java +++ b/java/com/facebook/csslayout/CSSNode.java @@ -494,8 +494,13 @@ public class CSSNode implements CSSNodeAPI { jni_CSSNodeSetHasMeasureFunc(mNativePointer, measureFunction != null); } + // Implementation Note: Why this method needs to stay final + // + // We cache the jmethodid for this method in CSSLayout code. This means that even if a subclass + // were to override measure, we'd still call this implementation from layout code since the + // overriding method will have a different jmethodid. This is final to prevent that mistake. @DoNotStrip - public long measure(float width, int widthMode, float height, int heightMode) { + public final long measure(float width, int widthMode, float height, int heightMode) { if (!isMeasureDefined()) { throw new RuntimeException("Measure function isn't defined!"); } diff --git a/java/jni/CSSJNI.cpp b/java/jni/CSSJNI.cpp index 3d9d488b..87c67cc8 100644 --- a/java/jni/CSSJNI.cpp +++ b/java/jni/CSSJNI.cpp @@ -51,8 +51,8 @@ static CSSSize _jniMeasureFunc(CSSNodeRef node, CSSMeasureMode heightMode) { auto obj = adopt_local(Environment::current()->NewLocalRef(reinterpret_cast(CSSNodeGetContext(node)))); - static auto measureFunc = - obj->getClass()->getMethod("measure"); + static auto measureFunc = findClassLocal("com/facebook/csslayout/CSSNode") + ->getMethod("measure"); _jniTransferLayoutDirection(node, obj); const auto measureResult = measureFunc(obj, width, widthMode, height, heightMode);