Skip to content


Browse files Browse the repository at this point in the history
Fix clone issue in YogaNodeJNIBase
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 4b92e2e commit 2707c17
Showing 1 changed file with 3 additions and 0 deletions.
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 2707c17

Please sign in to comment.