Make CSSNode#measure final, cache more correct methodid
Summary: In the JNI portion of CSSLayout, there's a subtle bug where we were caching the jmethodid of the 'measure' of the first object that had measure called on it. However, if that class had overriden measure, then the jmethodid would be specific to that subclass's implementation and would not work for other classes. Conversely, if a regular CSSNode had been called first, then the super method would be called on the subclass instead of the proper overriden method. Since there's not really a reason to overriden measure anyway (since you can just provide a different measure function), it's safest to just mark it final and explicitly cache the appropriate methodid Reviewed By: emilsjolander Differential Revision: D4132428 fbshipit-source-id: 6fb51597d80f1c03681e6611153b52b73b392245
This commit is contained in:
parent
a320b0ab19
commit
0089cd7630
|
@ -494,8 +494,13 @@ public class CSSNode implements CSSNodeAPI<CSSNode> {
|
|||
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!");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue