JavaFX silently swallowing exception raised in drag listeners

只谈情不闲聊 提交于 2019-12-01 11:39:05

问题


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)

回答1:


It appears that native method WinDnDClipboard.push(Object[], int) - backed by GlassClipboard.cpp swallows the exception silently. A call back to Throwable.getMessage() can be seen in the debugger but no exception is printed to the console.

The Java 9 version of this file (http://hg.openjdk.java.net/openjfx/9-dev/rt/file/1a3f128518cd/modules/javafx.graphics/src/main/native-glass/win/GlassClipboard.cpp) has an additional call to CheckAndClearException(env); as defined in Utils.cpp, however this is against RT-35400 which appears unrelated. This has not been backported to Java 8.



来源:https://stackoverflow.com/questions/43488321/javafx-silently-swallowing-exception-raised-in-drag-listeners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!