-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
jfx11, 10
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
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
- duplicates
-
JDK-8199614 [macos] ImageCursor.getBestSize() throws NullPointerException
-
- Resolved
-