Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8114459

NPE from Utils.getScreen()

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • fx2.0
    • fx2.0
    • javafx
    • None

      Utils.getScreen() doesn't handle the case when scene is not added to any Window. The test below throws the following exception:

      java.lang.NullPointerException
          at com.sun.javafx.Utils.getOffsetX(Utils.java:645)
          at com.sun.javafx.Utils.getScreen(Utils.java:778)
          at Test.start(Test.java:22)

      caused by the following code in Utils.getOffsetX():
                  return scene.getX() + scene.getWindow().getX();


      The test is

      import com.sun.javafx.Utils;
      import javafx.application.Application;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.shape.Rectangle;
      import javafx.stage.Stage;


      public class Test extends Application {
          
          public static void main(String[] args) {
              Application.launch(Test.class, args);
          }

          @Override public void start(Stage stage) {
              Rectangle r = new Rectangle();
              Scene sc = new Scene(new Group(r));
              System.out.println(Utils.getScreen(r));
          }
      }

            lnerad Ľubomír Nerád (Inactive)
            peterz Peter Zhelezniakov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: