Skip to content

Commit 2707c17

Browse files
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
1 parent 4b92e2e commit 2707c17

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

ReactAndroid/src/main/java/com/facebook/yoga/YogaNodeJNIBase.java

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ public void swapChildAt(YogaNode newChild, int position) {
116116
public YogaNodeJNIBase cloneWithChildren() {
117117
try {
118118
YogaNodeJNIBase clonedYogaNode = (YogaNodeJNIBase) super.clone();
119+
if (clonedYogaNode.mChildren != null) {
120+
clonedYogaNode.mChildren = new ArrayList<>(clonedYogaNode.mChildren);
121+
}
119122
long clonedNativePointer = YogaNative.jni_YGNodeCloneJNI(mNativePointer);
120123
clonedYogaNode.mOwner = null;
121124
clonedYogaNode.mNativePointer = clonedNativePointer;

0 commit comments

Comments
 (0)