-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
9
-
x86_64
-
windows_10
FULL PRODUCT VERSION :
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.16299.192]
A DESCRIPTION OF THE PROBLEM :
Adding a Shape node to a Pane root in the start method of a JavaFX application, the JavaFX application window is presented with the Shape drawn as expected, but shortly after a NPE is generated.
This occurs if passing the object to the Pane constructor, or if adding to the Pane object later with a root.getChildren().add(...) call.
The NPE is generated, but the window seems to be drawn correctly.
This is happening for multiple different Shape objects, but not a Text object.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
In a simple JavaFX application's start method:
- create a Rectangle object
- create a Pane object containing this rectangle
- create a Scene object containing this Pane
- update the stage with this Scene object
- wait briefly
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting the window and its children to be drawn without an exception.
ACTUAL -
A NPE is produced for each Shape object added to the Pane.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.graphics/com.sun.glass.ui.win.WinAccessible.getUnignoredChildren(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinAccessible.Navigate(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package drawing;
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.*;
public class DrawBug extends Application
{
private Scene scene;
private Pane root;
public void start(Stage stage)
{
Rectangle rect = new Rectangle(0, 0, 300, 200);
rect.setFill(Color.LIGHTGRAY);
Text text = new Text(50, 50, "Hello");
root = new Pane();
root.getChildren().addAll(rect, text);
// NOTE: Bug also happens with root = new Pane(rect, text);
root.setPrefSize(400, 300);
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
package drawing;
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.*;
public class DrawBugAvoided extends Application
{
private Scene scene;
private Pane root;
public void start(Stage stage)
{
Rectangle rect = new Rectangle(0, 0, 300, 200);
rect.setFill(Color.LIGHTGRAY);
Text text = new Text(50, 50, "Hello");
root = new Pane();
// Adding Shapes outside of the start method mostly works.
// Though if you do move the mouse quickly onto the region of
// the window that has the filled rectangle, it still generates the
// NPE.
root.setOnMouseEntered(event ->
{
if (root.getChildren().size() == 0)
root.getChildren().addAll(rect, text);
});
root.setPrefSize(400, 300);
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.16299.192]
A DESCRIPTION OF THE PROBLEM :
Adding a Shape node to a Pane root in the start method of a JavaFX application, the JavaFX application window is presented with the Shape drawn as expected, but shortly after a NPE is generated.
This occurs if passing the object to the Pane constructor, or if adding to the Pane object later with a root.getChildren().add(...) call.
The NPE is generated, but the window seems to be drawn correctly.
This is happening for multiple different Shape objects, but not a Text object.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
In a simple JavaFX application's start method:
- create a Rectangle object
- create a Pane object containing this rectangle
- create a Scene object containing this Pane
- update the stage with this Scene object
- wait briefly
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting the window and its children to be drawn without an exception.
ACTUAL -
A NPE is produced for each Shape object added to the Pane.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at javafx.graphics/com.sun.glass.ui.win.WinAccessible.getUnignoredChildren(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinAccessible.Navigate(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package drawing;
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.*;
public class DrawBug extends Application
{
private Scene scene;
private Pane root;
public void start(Stage stage)
{
Rectangle rect = new Rectangle(0, 0, 300, 200);
rect.setFill(Color.LIGHTGRAY);
Text text = new Text(50, 50, "Hello");
root = new Pane();
root.getChildren().addAll(rect, text);
// NOTE: Bug also happens with root = new Pane(rect, text);
root.setPrefSize(400, 300);
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
package drawing;
import javafx.application.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.*;
public class DrawBugAvoided extends Application
{
private Scene scene;
private Pane root;
public void start(Stage stage)
{
Rectangle rect = new Rectangle(0, 0, 300, 200);
rect.setFill(Color.LIGHTGRAY);
Text text = new Text(50, 50, "Hello");
root = new Pane();
// Adding Shapes outside of the start method mostly works.
// Though if you do move the mouse quickly onto the region of
// the window that has the filled rectangle, it still generates the
// NPE.
root.setOnMouseEntered(event ->
{
if (root.getChildren().size() == 0)
root.getChildren().addAll(rect, text);
});
root.setPrefSize(400, 300);
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
}
- duplicates
-
JDK-8189641 [Accessibility, windows] NPE when navigating to ComboBox with empty string
-
- Resolved
-