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

TableView: ArrayIndexOutOfBoundsException with cell selection / multiselection

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u65
    • javafx
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      JDK 1.8.0_45, 1.8.0_65

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When cell selection and multiple selection enabled in the TableView, I quite often get the ArrayIndexOutOfBoundsException during reordering of table columns. Cell selection does mostly only throw afterwards, i.e. TableView becomes unusable until recreated.
      The small test case attached

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) start the test case
      2) select all (ctrl+A) in the table
      3) move the column 'remark' between 'title' and 'author'

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      column moved, no exceptions
      ACTUAL -
      column moved, there is exception:
      Exception in thread "JavaFX Application Thread" java.lang.ArrayIndexOutOfBoundsException: -3
      at javafx.collections.transformation.SortedList.findPosition(SortedList.java:318)
      at javafx.collections.transformation.SortedList.removeFromMapping(SortedList.java:359)
      at javafx.collections.transformation.SortedList.addRemove(SortedList.java:389)
      at javafx.collections.transformation.SortedList.sourceChanged(SortedList.java:105)
      at javafx.collections.transformation.TransformationList.lambda$getListener$15(TransformationList.java:106)
      at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
      at com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:164)
      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.remove(ModifiableObservableListBase.java:183)
      at javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:171)
      at com.sun.javafx.scene.control.SelectedCellsMap.remove(SelectedCellsMap.java:194)
      at javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearSelection(TableView.java:2714)
      at javafx.scene.control.TableView$TableViewArrayListSelectionModel.access$1000(TableView.java:2028)
      at javafx.scene.control.TableView$5.onChanged(TableView.java:736)
      at javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
      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 com.sun.javafx.scene.control.skin.TableColumnHeader.moveColumn(TableColumnHeader.java:696)
      at com.sun.javafx.scene.control.skin.TableColumnHeader.columnReorderingComplete(TableColumnHeader.java:954)
      at com.sun.javafx.scene.control.skin.TableColumnHeader.lambda$static$55(TableColumnHeader.java:241)
      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$355(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$149(WinApplication.java:191)
      at java.lang.Thread.run(Thread.java:745)

      Any selection in the table afterwards results in an exception.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Book.java:
      package de.lexcom.tableview;

      import javafx.beans.property.SimpleStringProperty;

      public class Book {
          private SimpleStringProperty title = new SimpleStringProperty();
          private SimpleStringProperty author = new SimpleStringProperty();
          private SimpleStringProperty remark = new SimpleStringProperty();

          public Book(String title, String author, String remark) {
              super();
              setTitle(title);
              setAuthor(author);
              setRemark(remark);
          }

          public SimpleStringProperty titleProperty() {
              return this.title;
          }

          public java.lang.String getTitle() {
              return this.titleProperty().get();
          }

          public void setTitle(final java.lang.String title) {
              this.titleProperty().set(title);
          }

          public SimpleStringProperty authorProperty() {
              return this.author;
          }

          public java.lang.String getAuthor() {
              return this.authorProperty().get();
          }

          public void setAuthor(final java.lang.String author) {
              this.authorProperty().set(author);
          }

          public SimpleStringProperty remarkProperty() {
              return this.remark;
          }

          public java.lang.String getRemark() {
              return this.remarkProperty().get();
          }

          public void setRemark(final java.lang.String remark) {
              this.remarkProperty().set(remark);
          }

          @Override
          public String toString() {
              return String.format("%s(%s) - %s", getTitle(), getAuthor(), getRemark());
          }
      }



      FXTableViewExample3.java:
      package de.lexcom.tableview;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.scene.Scene;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.stage.Stage;

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

          private TableView<Book> table;

          @Override
          public void start(Stage primaryStage) {

              primaryStage.setTitle("Table View Example 3");

              // Table view, data, columns and properties
              table = new TableView<>();
              Book books[] = {
                      new Book("Book 1", "Author 1", "Remark 1")
                      , new Book("Book 2", "Author 2", "Remark 2")
                      , new Book("Book 3", "Author 3", "Remark 3")
                      , new Book("Book 4", "Author 4", "Remark 4")
              };
              table.setItems(FXCollections.observableArrayList());
              table.getItems().addAll(books);

              String[] columns = {
                  "title", "author", "remark"
              };
              for (String prop : columns) {
                  TableColumn<Book, String> col = new TableColumn<>(prop);
                  col.setCellValueFactory(new PropertyValueFactory<>(prop));
                  table.getColumns().add(col);
              }
              table.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY);
              table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              table.getSelectionModel().setCellSelectionEnabled(true);

              // Scene
              Scene scene = new Scene(table, 500, 475);
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None found so far ;(

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: