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

ListView's selected items list contains null elements although no items are null

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 8u60
    • javafx
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_66"
      Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When using a multiple selection mode, sometimes the list of selected items contains a null element, even though the list itself contains no null elements.

      It may be a regression introduced by this fix:

      http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/81af9caad4e2

      REGRESSION. Last worked in version 8u60

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_40"
      Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
      Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a list view with 3 items "1", "2", and "3" as in the code below.
      2. Select all 3 items in sequence with Ctrl-Click.
      3. Deselect the 2nd item with Ctrl-Click.
      4. Deselect the first item with Ctrl-Click.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code example gives the output:

      [1]
      [1, 2]
      [1, 2, 3]
      [1, 3]
      [3]
      ACTUAL -
      The code example gives the output:

      [1]
      [1, 2]
      [1, 2, 3]
      [1, 3]
      [null]

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ListChangeListener;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;

      import javafx.scene.control.ListView;
      import javafx.scene.control.SelectionMode;
      import javafx.stage.Stage;

      public class ListViewSelectionIssue extends Application {
          public static void main(String[] args) {
              Application.launch(args);
          }

          @Override public void start(Stage stage) {
              ListView<String> listView = new ListView<>();
              ObservableList<String> items = FXCollections.observableArrayList();

              listView.setItems(items);
              listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

              items.addAll("1", "2", "3");
              listView.getSelectionModel().getSelectedItems().addListener((ListChangeListener<String>) c -> {
                  System.out.println(listView.getSelectionModel().getSelectedItems());
              });

              Scene scene = new Scene(listView);
              stage.setScene(scene);
              stage.show();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call "get" on the "selected items" list elements twice, because only the first call returns null.

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: