-
Type:
Bug
-
Status: Resolved
-
Priority:
P4
-
Resolution: Duplicate
-
Affects Version/s: fx2.0
-
Fix Version/s: None
-
Component/s: javafx
-
Environment:
javafx 2.0 build 42, windows 7, jdk 7.0 netbeans 7.0.1
-
Subcomponent:
When setting scene.setOnDragOver() and scene.setOnDragDropped() appropriately to be run in an application just hit the alt key and you will receive a null pointer in your console.
To reproduce:
Step 1: Compile and run the attached file: DnDTest.java
Step 2: Hit the ALT key while having focus in the application window.
Step 3: Observe the stdout and see NPE
java.lang.NullPointerException
at com.sun.javafx.scene.KeyboardShortcutsHandler.processMnemonicsKeyDisplay(KeyboardShortcutsHandler.java:248)
at com.sun.javafx.scene.KeyboardShortcutsHandler.setMnemonicsDisplayEnabled(KeyboardShortcutsHandler.java:273)
at com.sun.javafx.scene.KeyboardShortcutsHandler.dispatchBubblingEvent(KeyboardShortcutsHandler.java:109)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:47)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$KeyHandler.process(Scene.java:2821)
at javafx.scene.Scene$KeyHandler.access$1500(Scene.java:2751)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1353)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:1784)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:105)
at com.sun.glass.ui.View.handleKeyEvent(View.java:248)
at com.sun.glass.ui.View.notifyKey(View.java:534)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
at java.lang.Thread.run(Thread.java:722)
Attached and appearing below is the code to reproduce issue:
import java.io.File;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
* @author cdea
*/
public class DnDTest extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 551, 400, Color.BLACK);
// Dragging over surface
scene.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
Dragboard db = event.getDragboard();
if (db.hasFiles()) {
event.acceptTransferModes(TransferMode.COPY);
} else {
event.consume();
}
}
});
// Dropping over surface
scene.setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles()) {
success = true;
for (File file:db.getFiles()) {
System.out.println("file: " + file);
}
}
event.setDropCompleted(success);
event.consume();
}
});
primaryStage.setScene(scene);
primaryStage.show();
}
}
To reproduce:
Step 1: Compile and run the attached file: DnDTest.java
Step 2: Hit the ALT key while having focus in the application window.
Step 3: Observe the stdout and see NPE
java.lang.NullPointerException
at com.sun.javafx.scene.KeyboardShortcutsHandler.processMnemonicsKeyDisplay(KeyboardShortcutsHandler.java:248)
at com.sun.javafx.scene.KeyboardShortcutsHandler.setMnemonicsDisplayEnabled(KeyboardShortcutsHandler.java:273)
at com.sun.javafx.scene.KeyboardShortcutsHandler.dispatchBubblingEvent(KeyboardShortcutsHandler.java:109)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:38)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:37)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:35)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:92)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:47)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:33)
at javafx.event.Event.fireEvent(Event.java:171)
at javafx.scene.Scene$KeyHandler.process(Scene.java:2821)
at javafx.scene.Scene$KeyHandler.access$1500(Scene.java:2751)
at javafx.scene.Scene.impl_processKeyEvent(Scene.java:1353)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Scene.java:1784)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(GlassViewEventHandler.java:105)
at com.sun.glass.ui.View.handleKeyEvent(View.java:248)
at com.sun.glass.ui.View.notifyKey(View.java:534)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$2$1.run(WinApplication.java:62)
at java.lang.Thread.run(Thread.java:722)
Attached and appearing below is the code to reproduce issue:
import java.io.File;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.input.DragEvent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
* @author cdea
*/
public class DnDTest extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Scene scene = new Scene(root, 551, 400, Color.BLACK);
// Dragging over surface
scene.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
Dragboard db = event.getDragboard();
if (db.hasFiles()) {
event.acceptTransferModes(TransferMode.COPY);
} else {
event.consume();
}
}
});
// Dropping over surface
scene.setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles()) {
success = true;
for (File file:db.getFiles()) {
System.out.println("file: " + file);
}
}
event.setDropCompleted(success);
event.consume();
}
});
primaryStage.setScene(scene);
primaryStage.show();
}
}