JDK-8189354 : Change.getRemoved() list contains incorrect selected items when a TreeItem is collapsed
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u144,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-10-16
  • Updated: 2021-05-14
  • Resolved: 2021-05-10
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.
Other
openjfx17Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
The related JDK-8152396 is marked as resolved - but isn't for all cases, actually fixed for 2 children ... 

To reproduce, take the example and increase the number of children:

        childNode1.getChildren().addAll(
            new TreeItem<String>("Node 1-1"),
            new TreeItem<String>("Node 1-2"),
//            new TreeItem<String>("Node 1-3"),
//            new TreeItem<String>("Node 1-4"),
//            new TreeItem<String>("Node 1-5"),
            new TreeItem<String>("Node 1-last")
        );

then expand/collapse until the exception with the same (modulo changes to the implementation managing the selectedItems, the current copied at the end) stacktrace as in the related issue is thrown - the number of exand/collapse cycles depends on the number of children:

for 3 children: happens in 5th expand
for 4 children: happens in 3th expand
(for >=5 children: happens in 1st collapse, but stacktrace different)

The underlying error is (still!) the incorrect change notification on remove (aka: collapse)

Listening to selectedItems with 4 children on expanding the selected parrent node, here the notification is correct, 4 items added to the list of selectedItems

List: { [TreeItem [ value: Node 1-1 ], TreeItem [ value: Node 1-2 ], TreeItem [ value: Node 1-3 ], TreeItem [ value: Node 1-last ]] added at 1 }
	cursor = 0
		Kind of change: added
		Affected range: [1, 5]
		Added size: 4
		Added sublist: [TreeItem [ value: Node 1-1 ], TreeItem [ value: Node 1-2 ], TreeItem [ value: Node 1-3 ], TreeItem [ value: Node 1-last ]]

Listening to selectedItems with 4 children on collapsing the selected parent node, here the notification is incorrect, only the first two children included in the removed list

 { [TreeItem [ value: Node 1-1 ], TreeItem [ value: Node 1-2 ]] removed at 1 }
	cursor = 0
		Kind of change: removed
		Affected range: [1, 1]
		Removed size: 2
		Removed: [TreeItem [ value: Node 1-1 ], TreeItem [ value: Node 1-2 ]]

The other way round: will pass (accidentally) for <= two children ..
 
Consequently, the filteredList gets out off sync. 

The stacktrace:

Exception in thread "JavaFX Application Thread" java.lang.ArrayIndexOutOfBoundsException
        at java.base/java.lang.System.arraycopy(Native Method)
        at javafx.base/javafx.collections.transformation.FilteredList.addRemove(FilteredList.java:274)
        at javafx.base/javafx.collections.transformation.FilteredList.sourceChanged(FilteredList.java:144)
        at javafx.base/javafx.collections.transformation.TransformationList.lambda$getListener$0(TransformationList.java:106)
        at javafx.base/javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
        at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
        at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
        at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
        at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
        at javafx.controls/com.sun.javafx.scene.control.SelectedItemsReadOnlyObservableList.lambda$new$1(SelectedItemsReadOnlyObservableList.java:103)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
        at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
        at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
        at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
        at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
        at javafx.controls/com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList._endChange(ReadOnlyUnbackedObservableList.java:63)
        at javafx.controls/javafx.scene.control.MultipleSelectionModelBase$SelectedIndicesList._endChange(MultipleSelectionModelBase.java:895)
        at javafx.controls/javafx.scene.control.ControlUtils.updateSelectedIndices(ControlUtils.java:202)
        at javafx.controls/javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.fireCustomSelectedCellsListChangeEvent(TreeTableView.java:3352)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
        at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
        at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
        at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
        at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
        at javafx.base/javafx.collections.transformation.SortedList.sourceChanged(SortedList.java:111)
        at javafx.base/javafx.collections.transformation.TransformationList.lambda$getListener$0(TransformationList.java:106)
        at javafx.base/javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
        at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
        at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
        at javafx.base/javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
        at javafx.base/javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
        at javafx.base/javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
        at javafx.base/javafx.collections.ModifiableObservableListBase.addAll(ModifiableObservableListBase.java:102)
        at javafx.controls/com.sun.javafx.scene.control.SelectedCellsMap.addAll(SelectedCellsMap.java:146)
        at javafx.controls/javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.selectIndices(TreeTableView.java:2951)
        at javafx.controls/javafx.scene.control.MultipleSelectionModel.selectRange(MultipleSelectionModel.java:180)
        at de.swingempire.fx.scene.control.selection.TreeTableSelection_original_8152396.selectChildrenOfRows(TreeTableSelection_original_8152396.java:100)






Comments
Changeset: eb913cb7 Author: mstr2 <43553916+mstr2@users.noreply.github.com> Committer: Ambarish Rapte <arapte@openjdk.org> Date: 2021-05-10 13:17:31 +0000 URL: https://git.openjdk.java.net/jfx/commit/eb913cb78bbc7a4973d1dfab3b02335edeff72aa
10-05-2021

- Issue is not reproducible on JDK 8GA - Issue is reproducible on JDK 8u144, JDK 8u152 - Issue is reproducible on JDK 9 GA and JDK 10 ea26
17-10-2017