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
This commit is contained in:
Pasquale Anatriello
2020-10-29 09:23:02 -07:00
committed by Facebook GitHub Bot
parent 64e2459427
commit 07eac0c6e2

View File

@@ -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;