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

ListView: IndexOutOfBoundsException in ListChangeListener

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u60
    • javafx
    • x86_64
    • linux_ubuntu

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      ListChangeListener.Change.getAddedSubList causes an IndexOutOfBoundsException if selecting items using Shift key. See steps to reproduce!

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Launch test case app
      Item <1> is selected
      2) Shift-Click on Item <2>
      Items <1> and <2> are selected
      3) Click on Item <3>
      Item <3> is selected and IndexOutOfBoundException is thrown.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package sample;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.collections.ListChangeListener;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.control.SelectionMode;
      import javafx.stage.Stage;

      public class Main extends Application {

          @Override
          public void start(Stage primaryStage) {
              final ListView<Integer> root = new ListView<>();
              root.setItems(FXCollections.observableArrayList(1,2,3));
              root.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              root.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Integer>)(c -> {
                  while (c.next()) {
                      if (c.wasAdded()) {
                          System.out.println(c.getAddedSubList());
                      }
                  }
              }));

              root.getSelectionModel().select(0);

              primaryStage.setScene(new Scene(root, 400, 400));
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: