Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TableView2 many IOOBEs are thrown when removing rows of selected cells #1503

Open
Pairoba opened this issue Jun 6, 2023 · 0 comments
Open

Comments

@Pairoba
Copy link

Pairoba commented Jun 6, 2023

I have a TableView2 with multi selection and cell selection enabled. (version 11.1.2)

  1. Select cells in multiple rows
  2. Clear table data
  3. Watch IndexOutOfBoundsExceptions being thrown

This exception is not thrown back into the user code, but having a lot of cells selected will result in a lot of exceptions. This creates a huge load, especially if these exceptions are logged to disk.

SSCCE:

import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.controlsfx.control.tableview2.TableColumn2;

public class TableView2TestBed extends Application
{
    @Override
    public void start(Stage primaryStage) throws Exception
    {
        TableView<String> tableView = new TableView2<>();
        tableView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        tableView.getSelectionModel().setCellSelectionEnabled(true);

        Button fill = new Button("fill");
        fill.setOnAction(event -> tableView.setItems(createSampleData()));
        Button clear = new Button("clear");
        clear.setOnAction(event -> tableView.getItems().clear());
        Button clearClear = new Button("clear selection & table");
        clearClear.setOnAction(event ->
        {
            tableView.getSelectionModel().clearSelection();
            tableView.getItems().clear();
        });

        TableColumn2<String, String> firstCol = new TableColumn2<>("First");
        firstCol.setCellValueFactory(p -> new SimpleStringProperty(p.getValue()));

        tableView.getColumns().add(firstCol);

        HBox buttons = new HBox(5, fill, clear, clearClear);
        primaryStage.setScene(new Scene(new VBox(5, buttons, tableView)));
        primaryStage.show();
    }

    private ObservableList<String> createSampleData()
    {
        return FXCollections.observableArrayList("A", "B", "C", "D", "E", "F", "G", "H", "I", "J");
    }
}

Console

Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException: Index 6 out of bounds for length 0
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
	at java.base/java.util.Objects.checkIndex(Objects.java:361)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at javafx.base/com.sun.javafx.collections.ObservableListWrapper.get(ObservableListWrapper.java:88)
	at javafx.controls/javafx.scene.control.TableView$TableViewSelectionModel.getModelItem(TableView.java:2192)
	at javafx.controls/javafx.scene.control.MultipleSelectionModelBase$1.getModelItem(MultipleSelectionModelBase.java:74)
	at javafx.controls/com.sun.javafx.scene.control.SelectedItemsReadOnlyObservableList.lambda$new$0(SelectedItemsReadOnlyObservableList.java:88)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:162)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:71)
	at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:238)
	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:210)
	at javafx.controls/com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList._endChange(ReadOnlyUnbackedObservableList.java:55)
	at javafx.controls/javafx.scene.control.MultipleSelectionModelBase$SelectedIndicesList._endChange(MultipleSelectionModelBase.java:917)
	at javafx.controls/javafx.scene.control.ControlUtils.updateSelectedIndices(ControlUtils.java:218)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.fireCustomSelectedCellsListChangeEvent(TableView.java:3186)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.lambda$new$1(TableView.java:2272)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:162)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:71)
	at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:238)
	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:210)
	at javafx.base/javafx.collections.transformation.SortedList.sourceChanged(SortedList.java:111)
	at javafx.base/javafx.collections.transformation.TransformationList.lambda$getListener$0(TransformationList.java:105)
	at javafx.base/javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:162)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:71)
	at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:238)
	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:210)
	at javafx.base/javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:190)
	at javafx.base/javafx.collections.ModifiableObservableListBase.remove(ModifiableObservableListBase.java:178)
	at javafx.controls/com.sun.javafx.scene.control.SelectedCellsMap.remove(SelectedCellsMap.java:194)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearSelection(TableView.java:2939)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearSelection(TableView.java:2913)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearSelection(TableView.java:2908)
	at impl.org.controlsfx.tableview2.RowHeader.lambda$init$12(RowHeader.java:210)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1092)
	at impl.org.controlsfx.tableview2.RowHeader.lambda$init$14(RowHeader.java:210)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper$SingleChange.fireValueChangedEvent(ListListenerHelper.java:162)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:71)
	at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:238)
	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:210)
	at javafx.base/javafx.collections.ModifiableObservableListBase.setAll(ModifiableObservableListBase.java:98)
	at impl.org.controlsfx.tableview2.TableView2Skin.updateHeaders(TableView2Skin.java:965)
	at impl.org.controlsfx.tableview2.TableView2Skin.lambda$init$9(TableView2Skin.java:532)
	at javafx.base/com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:360)
	at javafx.base/com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:80)
	at javafx.base/javafx.beans.property.ReadOnlyIntegerPropertyBase.fireValueChangedEvent(ReadOnlyIntegerPropertyBase.java:78)
	at javafx.base/javafx.beans.property.ReadOnlyIntegerWrapper.fireValueChangedEvent(ReadOnlyIntegerWrapper.java:102)
	at javafx.base/javafx.beans.property.IntegerPropertyBase.markInvalid(IntegerPropertyBase.java:114)
	at javafx.base/javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:148)
	at javafx.controls/javafx.scene.control.SelectionModel.setSelectedIndex(SelectionModel.java:69)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.updateSelectedIndex(TableView.java:3163)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.clearSelection(TableView.java:2953)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.updateDefaultSelection(TableView.java:3147)
	at javafx.controls/javafx.scene.control.TableView$TableViewArrayListSelectionModel.lambda$new$3(TableView.java:2340)
	at javafx.base/javafx.collections.WeakListChangeListener.onChanged(WeakListChangeListener.java:88)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:327)
	at javafx.base/com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:71)
	at javafx.base/javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:238)
	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:210)
	at javafx.base/com.sun.javafx.collections.ObservableListWrapper.clear(ObservableListWrapper.java:156)
	at TableView2TestBed.lambda$start$1(TableView2TestBed.java:29)
    /* ... */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant