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

8256283: IndexOutOfBoundsException when sorting a TreeTableView #384

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -579,7 +579,7 @@ public static int getNodeLevel(TreeItem<?> node) {
@Override public Boolean call(TreeTableView table) {
try {
TreeItem rootItem = table.getRoot();
if (rootItem == null) return false;
if (rootItem == null | rootItem.getChildren().isEmpty()) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be || (boolean OR). In addition to being less clear, this will get an NPE if rootItem is ever null, since the bit-wise | operator doesn't short-curcuit the rest of the if test if the first term is true.

Given that this would have caused a regression, and that we don't have a test that would catch it, can you add a test that sets the root to null and calls sort? It will fail with this version of the fix, but would pass without the fix and should pass once you update your fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, It was a typo. But it did reveal the missing test.
Corrected the operator to || and added a test as you suggested which fails only with the commit 1 of this PR.


TreeSortMode sortMode = table.getSortMode();
if (sortMode == null) return false;
Expand Down
Expand Up @@ -753,6 +753,25 @@ private void verifySelectionAfterPermutation() {
treeTableView.sort();
}

@Test public void testNoIOOBEWhenSortingAfterSelectAndClearRootChildren() {
TreeTableView<String> ttv = new TreeTableView<>();
TreeItem<String> root = new TreeItem<>("root");
TreeItem<String> child = new TreeItem<>("child");
root.getChildren().add(child);
root.setExpanded(true);
ttv.setRoot(root);
ttv.setShowRoot(false);

TreeTableColumn<String, String> ttc = new TreeTableColumn<>("Column");
ttv.getSortOrder().add(ttc);

ttv.getSelectionModel().select(0);
root.getChildren().remove(0);
ControlTestUtils.runWithExceptionHandler(() -> {
ttv.sort();
});
}

@Test public void testChangingSortPolicyUpdatesItemsList() {
TreeTableColumn<String, String> col = initSortTestStructure();
col.setSortType(DESCENDING);
Expand Down