nishihatapalmer / TreeTable

A Java Swing tree table using a standard JTable and any type of TreeNode or TreeModel.
BSD 3-Clause "New" or "Revised" License
6 stars 0 forks source link

IndexOutOfRangeException in TreeTableRowSorter if node is updated but no sort performed yet. #4

Closed nishihatapalmer closed 11 months ago

nishihatapalmer commented 11 months ago

If a node with no children is expanded, and the table has not yet been sorted, then in TreeTableRowSorter.rowsUpdated(), it tries to check valid last known indices. However, if a sort has never been performed, then this fails with an IndexOutOfRangeException.

nishihatapalmer commented 11 months ago

Interestingly, the TreeTableRowSorter implements the same behaviour in terms of throwing IndexOutOfBoundsExceptions as the DefaultRowSorter for a JTable. However, I guess there are some differences in terms of when this method is called during a row update.

Also need to check assumptions about index bounds when inserting and removing rows when sorting.

nishihatapalmer commented 11 months ago

So, contract of RowSorter states that attempts to update, remove or insert on row indexes that are outside the model range or where the first index is greater than the last index should throw an IndexOutOfBoundsException.

I have added a test that only checks whether updates are within bounds if sorting is actually enabled.