JDK-8204604 : [macOS] Image cursors throw NPE in Java 10 on OSX
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 10,openjfx11
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2018-06-07
  • Updated: 2018-06-08
  • Resolved: 2018-06-08
Related Reports
Duplicate :  
Description
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



Comments
This is a duplicate of JDK-8199614
08-06-2018

Issue is reproducible in macOS and not in windows. macOS High Sieraa 10.13.3, 64-bit JDK results: ------------------------ 8u172 : Pass 10+28 : Pass 10+29 : Fail <== Regression introduced here 10.0.1+10 : Fail 11-ea+13 : Fail ------------------
08-06-2018