Skip to content

Commit

Permalink
GP-4333: Avoid IOOBE from transitory table sort state.
Browse files Browse the repository at this point in the history
  • Loading branch information
nsadeveloper789 committed Feb 16, 2024
1 parent 6e615f1 commit 0c3ea62
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public String getHtmlDisplay() {
}
}

public record ValueAttribute<T> (ValueRow row, String name, Class<T> type)
public record ValueAttribute<T>(ValueRow row, String name, Class<T> type)
implements ValueProperty<T> {
public TraceObjectValue getEntry() {
return row.getAttributeEntry(name);
Expand Down Expand Up @@ -556,18 +556,39 @@ protected void resyncAttributeColumns(Collection<AttributeSchema> attributes) {
Set<DynamicTableColumn<ValueRow, ?, ?>> hiddenColumns =
new HashSet<>(computeAttributeColumns(byVisible.get(false)));
Set<DynamicTableColumn<ValueRow, ?, ?>> toRemove = new HashSet<>();
boolean[] removedIndices = new boolean[getColumnCount()];
for (int i = 0; i < getColumnCount(); i++) {
DynamicTableColumn<ValueRow, ?, ?> exists = getColumn(i);
if (!(exists instanceof AutoAttributeColumn)) {
continue;
}
if (!visibleColumns.remove(exists) && !hiddenColumns.remove(exists)) {
toRemove.add(exists);
removedIndices[i] = true;
}
}
TableSortState curSortState = getTableSortState();
TableSortStateEditor newStateEditor = new TableSortStateEditor();
for (ColumnSortState css : curSortState.getAllSortStates()) {
int index = css.getColumnModelIndex();
if (removedIndices[index]) {
continue; // Don't add too new
}
int precedingRemoved = 0;
for (int i = 0; i < index; i++) {
if (removedIndices[index]) {
precedingRemoved++;
}
}
newStateEditor.addSortedColumn(index - precedingRemoved, css.getSortDirection());
}
TableSortState newSortState = newStateEditor.createTableSortState();

setTableSortState(TableSortState.createUnsortedSortState());
removeTableColumns(toRemove);
addTableColumns(visibleColumns, true);
addTableColumns(hiddenColumns, false);
setTableSortState(newSortState);
}

@Override
Expand Down

0 comments on commit 0c3ea62

Please sign in to comment.