JDK-8169642 : IndexOutOfBoundsException when sorting TreeTableView with multi-selection enabled
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8u20,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-11-13
  • Updated: 2016-11-22
  • Resolved: 2016-11-22
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
9Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 10 x64

A DESCRIPTION OF THE PROBLEM :
When sorting the contents of a TreeTableView with multiple rows selected, a IndexOutOfBoundsException occurs (see stacktrace and sourcecode).

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Execute the sample app (see sourcecode)
2) Select more than one row
3) Click the column header to sort contents



ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException
	at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.subList(ReadOnlyUnbackedObservableList.java:136)
	at javafx.collections.ListChangeListener$Change.getAddedSubList(ListChangeListener.java:242)
	at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.handleSelectedCellsListChangeEvent(TreeTableView.java:3244)
	at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.access$2000(TreeTableView.java:2289)
	at javafx.scene.control.TreeTableView.sort(TreeTableView.java:1817)
	at javafx.scene.control.TreeTableView.doSort(TreeTableView.java:1855)
	at javafx.scene.control.TreeTableView.lambda$new$119(TreeTableView.java:828)
	at javafx.beans.WeakInvalidationListener.invalidated(WeakInvalidationListener.java:83)
	at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:349)
	at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
	at javafx.beans.property.ObjectPropertyBase.fireValueChangedEvent(ObjectPropertyBase.java:105)
	at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
	at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146)
	at javafx.scene.control.TreeTableColumn.setSortType(TreeTableColumn.java:448)
	at com.sun.javafx.scene.control.TableColumnSortTypeWrapper.setSortType(TableColumnSortTypeWrapper.java:60)
	at com.sun.javafx.scene.control.skin.TableColumnHeader.sortColumn(TableColumnHeader.java:770)
	at com.sun.javafx.scene.control.skin.TableColumnHeader.lambda$static$55(TableColumnHeader.java:243)
	at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
	at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
	at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
	at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
	at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
	at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
	at javafx.event.Event.fireEvent(Event.java:198)
	at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
	at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
	at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
	at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:352)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:275)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:388)
	at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
	at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:387)
	at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
	at com.sun.glass.ui.View.notifyMouse(View.java:937)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
	at java.lang.Thread.run(Thread.java:745)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.stage.Stage;

public class TreeTableViewSortBugTest extends Application{
	
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		final TreeItem<String> rootItem = new TreeItem<>("root");
		rootItem.getChildren().addAll(new TreeItem<>("first child"), new TreeItem<>("second child"));

		final TreeTableView<String> tree = new TreeTableView<>(rootItem);
		final TreeTableColumn<String, String> column = new TreeTableColumn<>("first column");
		column.setCellValueFactory(param -> new SimpleStringProperty(param.getValue().getValue()));
		tree.getColumns().add(column);
		tree.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
		
		final Scene scene = new Scene(tree);
		primaryStage.setScene(scene);
		primaryStage.sizeToScene();
		primaryStage.show();
	}
}

---------- END SOURCE ----------


Comments
Changeset: http://hg.openjdk.java.net/openjfx/9-dev/rt/rev/605946bd1d48
22-11-2016

+1
22-11-2016

Thanks for feedback - I have made all three suggested changes: http://cr.openjdk.java.net/~jgiles/8169642.1/
21-11-2016

SelectedItemsReadOnlyObservableList.eventBlock is now unused and may be deleted. final TreeItem<S> oldSelectedItem at the TreeTableView.java:2403 is also unused. I'm not sure about returning from the do-while loop here since theoretically we can have several changes...
21-11-2016

Webrev for review here: http://cr.openjdk.java.net/~jgiles/8169642/
21-11-2016

Checked this issue against 8uXX,9ea on Linux,Windows 7 and could reproduce the issue from JDK 8u20 onwards. Steps to reproduce: ************************* - Run the attached test application(TreeTableViewSortBugTest.java) with JDK. - Select more than one row - Click the column header to sort contents Result: ********* OS : Microsoft Windows 7 64 bit [Version 6.1.7601], Linux Ubuntu 14.04 LTS JDK: 8 b132 : Pass 8u5 b31 : Pass 8u11 b12 : Pass 8u20 b26 : Fail << Introduced Version 8u102 b14 : Fail 8u111 b14 : Fail 8u112 b16 : Fail 9ea+135 : Fail ================================================================================================================
14-11-2016