-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
7u80
-
Netbeans on Linux
-
x86_64
-
linux_ubuntu
FULL PRODUCT VERSION :
The project runs using java version "1.7.0_80"
ADDITIONAL OS VERSION INFORMATION :
Linux desktop 4.2.0-36-generic #42-Ubuntu SMP Thu May 12 22:05:35 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
To run the javafx application I'm using Netbeans IDE 8.1 using java version "1.8.0_91".
A DESCRIPTION OF THE PROBLEM :
When using a ListView with multiple selection if the first element of the view is selected, selectionModel.getSelectedIndices().contains() of that element always return false. For the other elements it works fine.
This is exactly the same bug asJDK-8125089, but it is marked as "Cannot Reproduce ". This bug stills affects JavaFx 2, but I think it is resolved in JavaFx 8.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I left a complete JUnit code to test the bug, the first test selects the first element of the ListView and fails, the second test selects the second element of the ListView and passes. Note that .indexOf() does work, and it is probably being used to implement .contains().
Both tests create a new ListView, add some elements to it, set the selection mode to multiple, select an element and check if the element is in the list of indices selected.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both tests should pass.
indices.contains(0) should return true
ACTUAL -
indices.contains(0) is returning false, even though 0 is in the list.
REPRODUCIBILITY :
This bug can be reproduced rarely.
---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ListView;
import javafx.scene.control.MultipleSelectionModel;
import javafx.scene.control.SelectionMode;
import org.junit.Test;
import static org.junit.Assert.*;
public class ObservableListTest {
public ObservableListTest() {
}
@Test
public void containsFirstElementTest() {
List<String> arrayList = new ArrayList();
arrayList.add("foo");
arrayList.add("bar");
arrayList.add("baz");
arrayList.add("qux");
ObservableList<String> list = FXCollections.observableArrayList(arrayList);
ListView<String> listview = new ListView<>();
listview.setItems(list);
listview.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
MultipleSelectionModel<String> selectionModel = listview.getSelectionModel();
// Select the first element
selectionModel.select(0);
ObservableList<Integer> indices = selectionModel.getSelectedIndices();
// Check that the first element is in the list of indices
assertTrue(indices.indexOf(0) >= 0);
assertTrue(indices.contains(0));
}
@Test
public void containsSecondElementTest() {
System.out.println(System.getProperty("java.version"));
List<String> arrayList = new ArrayList();
arrayList.add("foo");
arrayList.add("bar");
arrayList.add("baz");
arrayList.add("qux");
ObservableList<String> list = FXCollections.observableArrayList(arrayList);
ListView<String> listview = new ListView<>();
listview.setItems(list);
listview.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
MultipleSelectionModel<String> selectionModel = listview.getSelectionModel();
// select second element
selectionModel.select(1);
ObservableList<Integer> indices = selectionModel.getSelectedIndices();
// Check that the second element is in the list of indices
assertTrue(indices.indexOf(1) >= 0);
assertTrue(indices.contains(1));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use indices.indexOf instead of contains
The project runs using java version "1.7.0_80"
ADDITIONAL OS VERSION INFORMATION :
Linux desktop 4.2.0-36-generic #42-Ubuntu SMP Thu May 12 22:05:35 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
EXTRA RELEVANT SYSTEM CONFIGURATION :
To run the javafx application I'm using Netbeans IDE 8.1 using java version "1.8.0_91".
A DESCRIPTION OF THE PROBLEM :
When using a ListView with multiple selection if the first element of the view is selected, selectionModel.getSelectedIndices().contains() of that element always return false. For the other elements it works fine.
This is exactly the same bug as
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
I left a complete JUnit code to test the bug, the first test selects the first element of the ListView and fails, the second test selects the second element of the ListView and passes. Note that .indexOf() does work, and it is probably being used to implement .contains().
Both tests create a new ListView, add some elements to it, set the selection mode to multiple, select an element and check if the element is in the list of indices selected.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Both tests should pass.
indices.contains(0) should return true
ACTUAL -
indices.contains(0) is returning false, even though 0 is in the list.
REPRODUCIBILITY :
This bug can be reproduced rarely.
---------- BEGIN SOURCE ----------
import java.util.ArrayList;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.ListView;
import javafx.scene.control.MultipleSelectionModel;
import javafx.scene.control.SelectionMode;
import org.junit.Test;
import static org.junit.Assert.*;
public class ObservableListTest {
public ObservableListTest() {
}
@Test
public void containsFirstElementTest() {
List<String> arrayList = new ArrayList();
arrayList.add("foo");
arrayList.add("bar");
arrayList.add("baz");
arrayList.add("qux");
ObservableList<String> list = FXCollections.observableArrayList(arrayList);
ListView<String> listview = new ListView<>();
listview.setItems(list);
listview.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
MultipleSelectionModel<String> selectionModel = listview.getSelectionModel();
// Select the first element
selectionModel.select(0);
ObservableList<Integer> indices = selectionModel.getSelectedIndices();
// Check that the first element is in the list of indices
assertTrue(indices.indexOf(0) >= 0);
assertTrue(indices.contains(0));
}
@Test
public void containsSecondElementTest() {
System.out.println(System.getProperty("java.version"));
List<String> arrayList = new ArrayList();
arrayList.add("foo");
arrayList.add("bar");
arrayList.add("baz");
arrayList.add("qux");
ObservableList<String> list = FXCollections.observableArrayList(arrayList);
ListView<String> listview = new ListView<>();
listview.setItems(list);
listview.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
MultipleSelectionModel<String> selectionModel = listview.getSelectionModel();
// select second element
selectionModel.select(1);
ObservableList<Integer> indices = selectionModel.getSelectedIndices();
// Check that the second element is in the list of indices
assertTrue(indices.indexOf(1) >= 0);
assertTrue(indices.contains(1));
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
use indices.indexOf instead of contains