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

[macOS] Image cursors throw NPE in Java 10 on OSX

XMLWordPrintable

    • b29
    • 10
    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      OS: Mac High Sierra 10.13.5
      Java 10.0.1

      A DESCRIPTION OF THE PROBLEM :
      Setting the cursor on a control to use an ImageCursor will throw a NPE at runtime on Mac OSX (see stack trace below). Note: this works correctly on Java 9.0.4

      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.getBestCursorSize(CursorUtils.java:63)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.createPlatformImageCursor(CursorUtils.java:139)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.createPlatformImageCursor(CursorUtils.java:119)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.createPlatformCursor(CursorUtils.java:108)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.getPlatformCursor(CursorUtils.java:54)
      at javafx.graphics/com.sun.javafx.tk.quantum.ViewScene.lambda$setCursor$1(ViewScene.java:123)
      at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

      The issue appears to be related to the following method returning null on the Mac OSX (com.sun.glass.ui.Cursor):
      /**
           * Returns the 'best' cursor size based on the given preferred size.
           */
          public static Size getBestSize(int width, int height) {
              Application.checkEventThread();
              return Application.GetApplication().staticCursor_getBestSize(width, height);
          }



      REGRESSION : Last worked in version 8u172

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the "setCursor" method to change the cursor of a control with an ImageCursor


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the application should show the image cursor on top of the component.
      ACTUAL -
      NPE exception thrown by the runtime:

      Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.getBestCursorSize(CursorUtils.java:63)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.createPlatformImageCursor(CursorUtils.java:139)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.createPlatformImageCursor(CursorUtils.java:119)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.createPlatformCursor(CursorUtils.java:108)
      at javafx.graphics/com.sun.javafx.tk.quantum.CursorUtils.getPlatformCursor(CursorUtils.java:54)
      at javafx.graphics/com.sun.javafx.tk.quantum.ViewScene.lambda$setCursor$1(ViewScene.java:123)
      at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

      ---------- BEGIN SOURCE ----------
      package test;

      import java.io.File;

      import javafx.application.Application;
      import javafx.scene.ImageCursor;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.image.Image;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;


      public class TestImageCursor extends Application
      {
        @Override
        public void start(Stage stage)
        {
          Button btn = new Button("Test");
          btn.setOnAction(e -> {
            File imgFile = new File("./images/cursors/select_move.png");
            Image img = new Image(imgFile.toURI().toString());
            System.err.println("creating image cursor: " + img.getWidth() + "," + img.getHeight());
            btn.setCursor(new ImageCursor(img));
          });
          final Scene scene=new Scene(new BorderPane(btn), 300, 250);
          stage.setScene(scene);
          stage.show();
        }

        public static void main(String[] args)
        {
          launch(args);
        }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: