Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8185128

IndexOutOfBoundsException in TreeTableView when reordering a column that has multiple selected cells

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      Java 8.0_131

      ADDITIONAL OS VERSION INFORMATION :
      macOS Sierra Version 10.12.6

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      This issue has also been reported (not by me) in StackOverflow here:
      https://stackoverflow.com/questions/29134625/javafx-treetableview-exception-when-sorting-with-multiple-rows-selected

      A DESCRIPTION OF THE PROBLEM :
      In a TreeTableView with selectionMode set to multiple, if you multi select some cells and then reorder, you will get an IndexOutOfBoundsException.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the sample code, expand the root node and multi select some cells. Then re-order the column.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Column should reorder without an IndexOutOfBoundsException.
      ACTUAL -
      App crashes with an IndexOutOfBoundsException

      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$114(TreeTableView.java:383)
      at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
      at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
      at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
      at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
      at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
      at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
      at javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:90)
      at javafx.collections.ObservableListBase.setAll(ObservableListBase.java:250)
      at com.sun.javafx.scene.control.skin.TableColumnHeader.sortColumn(TableColumnHeader.java:795)
      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:381)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
      at java.security.AccessController.doPrivileged(Native Method)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
      at com.sun.glass.ui.View.notifyMouse(View.java:937)

      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.scene.layout.StackPane;
      import javafx.stage.Stage;


      public class TreeViewSample extends Application {

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) {
              
              TreeItem<String> treeItemRoot = new TreeItem<> ("Root");
              
              TreeItem<String> nodeItemA = new TreeItem<>("Item A");
              TreeItem<String> nodeItemB = new TreeItem<>("Item B");
              TreeItem<String> nodeItemC = new TreeItem<>("Item C");
              treeItemRoot.getChildren().addAll(nodeItemA, nodeItemB, nodeItemC);
              
              
              TreeTableView<String> treeView = new TreeTableView<>(treeItemRoot);
              treeView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              StackPane root = new StackPane();
              root.getChildren().add(treeView);
              
              
              TreeTableColumn<String, String> column = new TreeTableColumn<>();
              column.setCellValueFactory(value ->
              {
                  return new SimpleStringProperty(value.getValue().getValue());
              });
              column.setPrefWidth(100);
              
              treeView.getColumns().add(column);
              
              Scene scene = new Scene(root, 300, 250);
              
              primaryStage.setTitle("java-buddy.blogspot.com");
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Have to clear the selection before sorting.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: