-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
8u51
-
x86
-
windows_8
FULL PRODUCT VERSION :
C:\Users\Owner>java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
C:\Users\Owner>
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Owner>ver
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
When removing a child node from a parent for all other controls including BorderPane or any other layout the child's parent will be set to null allowing it to be added to other layouts or set as the root of a scene. SplitPane however does not follow the required invariants outlined in the parent source code as a result of its styling abstraction.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a SplitPane and add a new node, any type of node, to the SplitPane using getItems()
After you add it immediately remove it using the same getItems() interface i.e. getItems().remove(node)
Once you have removed it from the SplitPane then try to construct a new Scene or set it as the root of an existing scene and it will throw an exception.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected result is that no exception will be thrown and the node will be properly set as the root of a new scene. The expected result is also that node.getParent() just after removing it from SplitPane and just before adding it to a new parent will return null as every other layout or parent is expected to do.
ACTUAL -
An exception was thrown and the node's getParent() method still returned SplitPaneSkin$Content@1384df6 long after it had already been removed from the split pane.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Node@800d3ais already inside a scene-graph and cannot be set as root
at javafx.scene.Scene$9.invalidated(Unknown Source)
at javafx.beans.property.ObjectPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.ObjectPropertyBase.set(Unknown Source)
at javafx.scene.Scene.setRoot(Unknown Source)
at javafx.scene.Scene.<init>(Unknown Source)
at javafx.scene.Scene.<init>(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
SplitPane split = new SplitPane();
Label label = new Label("test");
split.getItems().add(label);
split.getItems().remove(label);
label.getParent(); // should return null but returns SplitPaneSkin$Content@1384df6
Scene scene = new Scene(label); // exception because parent is not null
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
A temporary work around is to create a BorderPane and add the removed node to it and then quickly remove it again to have the node's parent set to null. For example, you could do the following before constructing a scene with the new node.
BorderPane borderPane = new BorderPane();
borderPane.setCenter(label);
borderPane.setCenter(null);
label.getParent(); // correctly returns null
Scene scene = new Scene(label); // works perfectly!
SUPPORT :
YES
C:\Users\Owner>java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
C:\Users\Owner>
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Owner>ver
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
When removing a child node from a parent for all other controls including BorderPane or any other layout the child's parent will be set to null allowing it to be added to other layouts or set as the root of a scene. SplitPane however does not follow the required invariants outlined in the parent source code as a result of its styling abstraction.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a SplitPane and add a new node, any type of node, to the SplitPane using getItems()
After you add it immediately remove it using the same getItems() interface i.e. getItems().remove(node)
Once you have removed it from the SplitPane then try to construct a new Scene or set it as the root of an existing scene and it will throw an exception.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected result is that no exception will be thrown and the node will be properly set as the root of a new scene. The expected result is also that node.getParent() just after removing it from SplitPane and just before adding it to a new parent will return null as every other layout or parent is expected to do.
ACTUAL -
An exception was thrown and the node's getParent() method still returned SplitPaneSkin$Content@1384df6 long after it had already been removed from the split pane.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: Node@800d3ais already inside a scene-graph and cannot be set as root
at javafx.scene.Scene$9.invalidated(Unknown Source)
at javafx.beans.property.ObjectPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.ObjectPropertyBase.set(Unknown Source)
at javafx.scene.Scene.setRoot(Unknown Source)
at javafx.scene.Scene.<init>(Unknown Source)
at javafx.scene.Scene.<init>(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
SplitPane split = new SplitPane();
Label label = new Label("test");
split.getItems().add(label);
split.getItems().remove(label);
label.getParent(); // should return null but returns SplitPaneSkin$Content@1384df6
Scene scene = new Scene(label); // exception because parent is not null
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
A temporary work around is to create a BorderPane and add the removed node to it and then quickly remove it again to have the node's parent set to null. For example, you could do the following before constructing a scene with the new node.
BorderPane borderPane = new BorderPane();
borderPane.setCenter(label);
borderPane.setCenter(null);
label.getParent(); // correctly returns null
Scene scene = new Scene(label); // works perfectly!
SUPPORT :
YES
- relates to
-
JDK-8148828 SplitPane Child Does Not Have null Parent After Being Removed
-
- Resolved
-