Skip to content

Commit

Permalink
instance of checks for YogaNodeJniBase
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[Internal][Yoga] - Added instance of checks in `YogaNodeJNIBase` class to prevent `ClassCastException`s. This was happening for some NT android tests - Mocked Yoga Node object was being passed in the `addChildAt` api

Stack Trace of exception
    java.lang.ClassCastException: com.facebook.yoga.YogaNode$MockitoMock$1408896622 cannot be cast to com.facebook.yoga.YogaNodeJNIBase
	at com.facebook.yoga.YogaNodeJNIBase.addChildAt(YogaNodeJNIBase.java:86)
	at com.facebook.litho.DefaultInternalNode.addChildAt(DefaultInternalNode.java:220)
	at com.facebook.litho.DefaultInternalNode.child(DefaultInternalNode.java:377)
	at com.facebook.litho.DefaultInternalNode.child(DefaultInternalNode.java:360)
	at com.facebook.litho.Column.resolve(Column.java:118)
	at com.facebook.litho.Layout.create(Layout.java:172)

Reviewed By: Andrey-Mishanin

Differential Revision: D26114992

fbshipit-source-id: 774a689609e67f9244b81c6788b62cd61cd96d14
  • Loading branch information
SidharthGuglani-zz authored and facebook-github-bot committed Feb 5, 2021
1 parent 95cab24 commit 96bc33a
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public YogaNodeJNIBase getChildAt(int i) {
}

public void addChildAt(YogaNode c, int i) {
if (!(c instanceof YogaNodeJNIBase)) {
return;
}
YogaNodeJNIBase child = (YogaNodeJNIBase) c;
if (child.mOwner != null) {
throw new IllegalStateException("Child already has a parent, it must be removed first.");
Expand All @@ -105,6 +108,9 @@ public boolean isReferenceBaseline() {
}

public void swapChildAt(YogaNode newChild, int position) {
if (!(newChild instanceof YogaNodeJNIBase)) {
return;
}
YogaNodeJNIBase child = (YogaNodeJNIBase) newChild;
mChildren.remove(position);
mChildren.add(position, child);
Expand Down Expand Up @@ -223,6 +229,9 @@ public boolean isDirty() {

@Override
public void copyStyle(YogaNode srcNode) {
if (!(srcNode instanceof YogaNodeJNIBase)) {
return;
}
YogaNative.jni_YGNodeCopyStyleJNI(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer);
}

Expand Down

0 comments on commit 96bc33a

Please sign in to comment.