Skip to content

Commit 1be2541

Browse files
ayc1facebook-github-bot
authored andcommitted
Add assertion to ensure copied shadow nodes are of the same type as the original
Reviewed By: mdvacca Differential Revision: D7664638 fbshipit-source-id: e1b7acbafd8a8fd9d6301d8afbb3e5959dc15b7a
1 parent 3145b1e commit 1be2541

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactShadowNodeImpl.java

+6
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ protected ReactShadowNodeImpl copy() {
166166
@Override
167167
public ReactShadowNodeImpl mutableCopy() {
168168
ReactShadowNodeImpl copy = copy();
169+
Assertions.assertCondition(
170+
getClass() == copy.getClass(),
171+
"Copied shadow node must use the same class");
169172
if (mYogaNode != null) {
170173
copy.mYogaNode = mYogaNode.clone();
171174
copy.mYogaNode.setData(copy);
@@ -182,6 +185,9 @@ public ReactShadowNodeImpl mutableCopy() {
182185
@Override
183186
public ReactShadowNodeImpl mutableCopyWithNewChildren() {
184187
ReactShadowNodeImpl copy = copy();
188+
Assertions.assertCondition(
189+
getClass() == copy.getClass(),
190+
"Copied shadow node must use the same class");
185191
if (mYogaNode != null) {
186192
copy.mYogaNode = mYogaNode.cloneWithNewChildren();
187193
copy.mYogaNode.setData(copy);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2004-present Facebook. All Rights Reserved.
2+
package com.facebook.react.fabric;
3+
4+
import com.facebook.react.uimanager.ReactShadowNodeImpl;
5+
import com.facebook.testing.robolectric.v3.WithTestDefaultsRunner;
6+
import org.junit.Test;
7+
import org.junit.runner.RunWith;
8+
9+
/** Tests {@link ReactShadowNode} */
10+
@RunWith(WithTestDefaultsRunner.class)
11+
public class ReactShadowNodeTest {
12+
13+
@Test(expected = AssertionError.class)
14+
public void testClonedInstance() {
15+
TestReactShadowNode node = new TestReactShadowNode();
16+
node.mutableCopy();
17+
}
18+
19+
private static class TestReactShadowNode extends ReactShadowNodeImpl {}
20+
}

0 commit comments

Comments
 (0)