JDK-8146919 : sometimes getting selected items from a listview returns null when it should not
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u66
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2016-01-11
  • Updated: 2016-06-07
  • Resolved: 2016-01-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Relates :  
Description
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");


Comments
Nice.
13-01-2016

Fortuitously I just fixed JDK-8144501 yesterday, which does indeed resolve this issue. JDK-8144501 was a really frustrating bug to resolve as it was excellent at hiding itself when debugging, and I'm sure that there will be other bugs that are fixed by JDK-8144501 also.
13-01-2016

This looks like a duplicate of JDK-8144501. At least I verified that this bug is no longer happening after the fix for JDK-8144501 fixes the problem. Assigning to Jonathan to confirm this. If so, then it should be closed as a duplicate.
13-01-2016

I note that this fails for me on JDK 8u66 (and also 8u72) and passes on JDK 9.
13-01-2016

Attached a test case provided by David Gilbert.
13-01-2016

I received the following comment in e-mail from David Gilbert: > In our application we are seeing the same issue in a TableView, so I guess it is more likely to be in the selection model rather than the ListView or TableView controls.
13-01-2016

This might be a bug in ListView itself, in which case it should be moved to controls.
12-01-2016