javafxports / openjdk-jfx

The openjfx repo has moved to:
https://github.com/openjdk/jfx
GNU General Public License v2.0
1.01k stars 145 forks source link

ListView: IndexOutOfBoundsException in ListChangeListener #315

Open VenatorX opened 5 years ago

VenatorX commented 5 years ago

Hello, I 'm reposting a bug reported on jdk bug tracker that is still unresolved. Thank you for your help.

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 ----------

nlisker commented 5 years ago
  1. Please add a link to the JBS bug on the top of the comment.
  2. Add the identifier ("JDK-xxxxx") to the title.
  3. Format the code properly. Not sure why you want to copy-paste it, do you want to discuss something?