Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8128883

Drag and Drop receives a null pointer exception when hitting a the ALT key

    Details

      Description

      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();
          }
          
      }

        Attachments

          Activity

            People

            • Assignee:
              miflemi Mick Fleming (Inactive)
              Reporter:
              cdea Carl Dea
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: