FULL PRODUCT VERSION :
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b18)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b18, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601
A DESCRIPTION OF THE PROBLEM :
multiselecting one item, then adding to the selection an item at a higher index, then deselecting the item at the lower index and calling getselectedItems returns a null item instead of the item at the higher index
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
select the first index of a listview in multiselection mode, then select the second index both are now select, deselect the first index, now just the second index should be selected. and call getSelectedItems. it will return an observable list with a single null item
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
using the example code provided getSelectedItems should return a list with one item in it, "one" the item at index 1
ACTUAL -
using the example code provided getSelectedItems returns a list with one item in it that is null
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
ListView<String> list = new ListView<>();
ObservableList<String> items = FXCollections.observableArrayList("zero", "one", "two", "three", "four", "five");
list.setItems(items);
list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
list.getSelectionModel().select(0);
list.getSelectionModel().select(1);
list.getSelectionModel().clearSelection(0);
ObservableList<String> selectedItems = list.getSelectionModel().getSelectedItems();
while (selectedItems.get(0) == null) {
System.err.println("FAILED: selected item is null"); //triggers once
}
System.err.println("SUCCESS: selected item = " + selectedItems.get(0));
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
this code will get the incorrect null value once and for some reason the next time it trys to get the value it is no longer null
while (selectedItems.get(0) == null) {
System.err.println("Keep Waiting: Selected Item is still null"); //triggers once
}
System.err.println("SUCCESS");