It appears that exceptions are silently swallowed in drag over listeners in JavaFX. I've searched and can't find any mention of this in the documentation.
I've recreated this below...
Is there anyway to prevent this and expose the exceptions?
public class App extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Button source = new Button("source");
Button destination = new Button("destination");
HBox box = new HBox(source, destination);
source.setOnDragDetected(event -> {
Dragboard db = source.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.putString("foo");
db.setContent(content);
event.consume();
});
destination.setOnDragOver(new EventHandler<DragEvent>() {
public void handle(DragEvent event) {
event.acceptTransferModes(TransferMode.LINK);
String nullReference = null;
nullReference.toCharArray(); // cause an exception
event.consume();
}
});
primaryStage.setScene(new Scene(box));
primaryStage.show();
}
}
Following feedback from James_D and further investigation, we have found this varies by platform
- Ubuntu Linux. 1.8.0_40 => exceptions seen
- Mac OS X. 1.8.0_40 => exceptions seen
- Windows 7. 1.8.0_40 => No exceptions
- Windows 7. 1.8.0_121 => No exceptions (latest JDK at time of writing)