|
16 | 16 |
|
17 | 17 | package com.vaadin.flow.internal; |
18 | 18 |
|
| 19 | +import java.lang.reflect.Field; |
19 | 20 | import java.util.ArrayList; |
20 | 21 | import java.util.Arrays; |
21 | 22 | import java.util.HashSet; |
@@ -296,6 +297,35 @@ public void nodeTreeOnAttach_bottomUpTraversing_correctOrder() { |
296 | 297 | data.removeLast())); |
297 | 298 | } |
298 | 299 |
|
| 300 | + @Test |
| 301 | + public void nodeTreeOnAttach_bottomUpTraversing_brokenParentInChildDoesNotEndInLoop() |
| 302 | + throws NoSuchFieldException, IllegalAccessException { |
| 303 | + // Set data is used to track the node during debug see |
| 304 | + // TestStateNode.toString |
| 305 | + TestStateNode root = new TestStateNode(); |
| 306 | + root.setData(0); |
| 307 | + List<Integer> count = new ArrayList<>(); |
| 308 | + |
| 309 | + final Field parent = StateNode.class.getDeclaredField("parent"); |
| 310 | + parent.setAccessible(true); |
| 311 | + |
| 312 | + TestStateNode childOfRoot = new TestStateNode(); |
| 313 | + childOfRoot.setData(1); |
| 314 | + |
| 315 | + TestStateNode child = new TestStateNode(); |
| 316 | + child.setData(2); |
| 317 | + setParent(child, childOfRoot); |
| 318 | + |
| 319 | + parent.set(child, null); |
| 320 | + |
| 321 | + setParent(childOfRoot, root); |
| 322 | + |
| 323 | + root.visitNodeTreeBottomUp(node -> count.add(1)); |
| 324 | + |
| 325 | + Assert.assertEquals("Each node should be visited once", 3, |
| 326 | + count.size()); |
| 327 | + } |
| 328 | + |
299 | 329 | @Test |
300 | 330 | public void attachListener_onSetParent_listenerTriggered() { |
301 | 331 | StateNode root = new TestStateTree().getRootNode(); |
|
0 commit comments