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

[Drag and Drop, Windows] COM error when doing DnD on a ListView with null items list

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u20
    • javafx
    • None

      I was looking into RT-36686 and run into an interesting bug which appears to be occuring at the glass level, so I thought I better report it.

      Steps to reproduce:
      1) Open the HelloListView class file.
      2) Search for the line: listTwo.setItems(listTwoItems);
      3) Replace with: listTwo.setItems(null);
      4) Run HelloListView
      5) Go to the 'DnD' tab
      6) Drag an item from the left ListView to the right ListView
      7) On my Windows 8 machine, I got the exception in the attached screenshot (sorry about the screenshot, for whatever reason IntelliJ was not allowing for copy/paste).

      The reason why this occurs is obvious - in HelloListView there is the following code (note the comment):

      EventHandler<DragEvent> dragDropped = new EventHandler<DragEvent>() {
          public void handle(DragEvent event) {
              ListView<String> list = (ListView) event.getGestureTarget();

              Dragboard db = event.getDragboard();
              boolean success = false;
              if (db.hasString()) {
                  list.getItems().add(db.getString()); // <------- list.getItems() is null, so we're getting a NPE here.
                  success = true;
              }

              event.setDropCompleted(success);
              event.consume();
          }
      };

            morris Morris Meyer (Inactive)
            jgiles Jonathan Giles
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: