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

[TableView] IOOBE when using bindings API with SelectionModel selectedItems list

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8u40
    • 8u40
    • javafx
    • None

    Description

      Steps to reproduce:
      1) Load test application below
      2) Press ctrl-A to select all rows
      3) With mouse, click on one of the rows
      4) Press ctrl-A again
      5) With mouse, click on one of the rows -> bug - IOOBE

      import javafx.application.Application;
      import javafx.beans.binding.Bindings;
      import javafx.beans.property.IntegerProperty;
      import javafx.beans.property.SimpleIntegerProperty;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.collections.FXCollections;
      import javafx.collections.ListChangeListener;
      import javafx.collections.ObservableList;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.control.cell.PropertyValueFactory;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class TableTest extends Application {
          private ObservableList<Person> _selectedPersons;
          private TableView<Person> _personTable;

          @Override
          public void start(Stage primaryStage) {
              BorderPane root = new BorderPane();
              Scene scene = new Scene(root, 600, 400);

              ObservableList<Person> personList = FXCollections.observableArrayList();
              Person person1 = new Person("name1", 12);
              Person person2 = new Person("name2", 33);
              Person person3 = new Person("name3", 44);
              Person person4 = new Person("name4", 44);
              Person person5 = new Person("name5", 44);
              Person person6 = new Person("name6", 44);

              personList.setAll(person1, person2, person3, person4, person5, person6);

              _personTable = new TableView<>();
              _personTable.setEditable(true);
              _personTable.setTableMenuButtonVisible(true);
              _personTable.setItems(personList);

              _personTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

              TableColumn<Person, String> nameColumn = new TableColumn<>("Name");
              nameColumn.setCellValueFactory(new PropertyValueFactory<>("name"));

              nameColumn.setGraphic(new Label("Name"));
              nameColumn.setText("Name");

              TableColumn<Person, Integer> ageColumn = new TableColumn<>("Age");
              ageColumn.setCellValueFactory(new PropertyValueFactory<>("age"));

              _personTable.getColumns().addAll(nameColumn, ageColumn);

              root.setCenter(_personTable);

              primaryStage.setScene(scene);
              primaryStage.show();

              _selectedPersons = FXCollections.observableArrayList();

              _personTable.getSelectionModel().getSelectedItems().addListener((ListChangeListener<Person>) change -> {
                  while (change.next()) {
                      System.err.println("number of selected persons (in selectionModel): " + change.getList().size());
                  }
              });

              _selectedPersons.addListener((ListChangeListener<Person>) change -> {
                  while (change.next()) {
                      System.err.println("number of selected persons (in bound list): " + change.getList().size());
                  }
              });

              Bindings.bindContent(_selectedPersons, _personTable.getSelectionModel().getSelectedItems());
          }

          public static void main(String[] args) {
              launch(args);
          }

          public static class Person {
              private StringProperty nameProperty = new SimpleStringProperty();
              private IntegerProperty ageProperty = new SimpleIntegerProperty();

              public Person(String name, Integer age) {
                  setName(name);
                  setAge(age);
              }

              public StringProperty nameProperty() {
                  return nameProperty;
              }

              public void setName(String name) {
                  nameProperty.set(name);
              }

              public String getName() {
                  return nameProperty.get();
              }

              public IntegerProperty ageProperty() {
                  return ageProperty;
              }

              public void setAge(Integer age) {
                  ageProperty.set(age);
              }

              public Integer getAge() {
                  return ageProperty.get();
              }

              @Override
              public String toString() {
                  return "" + getName() + "/" + getAge();
              }
          }
      }


      Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: toIndex = 6
      at java.util.SubList.<init>(AbstractList.java:622)
      at java.util.RandomAccessSubList.<init>(AbstractList.java:775)
      at java.util.AbstractList.subList(AbstractList.java:484)
      at javafx.collections.ModifiableObservableListBase.subList(ModifiableObservableListBase.java:189)
      at com.sun.javafx.binding.ContentBinding$ListContentBinding.onChanged(ContentBinding.java:111)
      at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
      at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
      at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.callObservers(ReadOnlyUnbackedObservableList.java:75)
      at javafx.scene.control.TableView$TableViewArrayListSelectionModel.handleSelectedCellsListChangeEvent(TableView.java:3021)
      at javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearAndSelect(TableView.java:2394)
      at javafx.scene.control.TableView$TableViewSelectionModel.clearAndSelect(TableView.java:1898)
      at com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.simpleSelect(TableCellBehaviorBase.java:215)
      at com.sun.javafx.scene.control.behavior.TableCellBehaviorBase.doSelect(TableCellBehaviorBase.java:197)
      at com.sun.javafx.scene.control.behavior.CellBehaviorBase.mouseReleased(CellBehaviorBase.java:159)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
      at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
      at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      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.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:3728)
      at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3456)
      at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1732)
      at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2465)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:350)
      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$3(GlassViewEventHandler.java:385)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler$$Lambda$267/19057018.get(Unknown Source)
      at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:404)
      at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:384)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
      at com.sun.glass.ui.View.notifyMouse(View.java:927)
      at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
      at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:101)
      at com.sun.glass.ui.win.WinApplication$$Lambda$38/25843178.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:745)

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported: