From 07eac0c6e21bf0ddbe5e87bd18a8940cff83a0b8 Mon Sep 17 00:00:00 2001 From: Pasquale Anatriello Date: Thu, 29 Oct 2020 09:23:02 -0700 Subject: [PATCH] Fix clone issue in YogaNodeJNIBase 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 --- java/com/facebook/yoga/YogaNodeJNIBase.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index 406e75e5..7ab391cc 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -116,6 +116,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { 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;