Skip to content

Commit

Permalink
Fix clone issue in YogaNodeJNIBase
Browse files Browse the repository at this point in the history
Summary:
Changelog:
Fix the cloneWithChildren implementation that was not copying the list of children on the java object.

We were missing on copying the list of children when cloning. This is pretty bad as it means that the clone operation was mutating the old node as well as the new. When multiple threads were involved this could cause crashes.

Reviewed By: SidharthGuglani

Differential Revision: D24565307

fbshipit-source-id: 4e2e111db389e25c315ce7603b4018ac695bb0f1
  • Loading branch information
pasqualeanatriello authored and facebook-github-bot committed Oct 29, 2020
1 parent 64e2459 commit 07eac0c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions java/com/facebook/yoga/YogaNodeJNIBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public void swapChildAt(YogaNode newChild, int position) {
public YogaNodeJNIBase cloneWithChildren() {
try {
YogaNodeJNIBase clonedYogaNode = (YogaNodeJNIBase) super.clone();
if (clonedYogaNode.mChildren != null) {
clonedYogaNode.mChildren = new ArrayList<>(clonedYogaNode.mChildren);
}
long clonedNativePointer = YogaNative.jni_YGNodeCloneJNI(mNativePointer);
clonedYogaNode.mOwner = null;
clonedYogaNode.mNativePointer = clonedNativePointer;
Expand Down

0 comments on commit 07eac0c

Please sign in to comment.