JetBrains/intellij-community · error · IllegalArgumentException
"Starting index " + startingIdx + " is greater than the tota
Error message
"Starting index " + startingIdx + " is greater than the total number of rows " + getRowsNum() + ". Starting index should be less or equal to " + getRowsNum()
What it means
DynamicNestedTable.insertRows(int, List<GridRow>) throws IllegalArgumentException when startingIdx exceeds the current row count. Insertion at the very end (startingIdx == getRowsNum()) is legal; anything beyond that would leave a gap in the row list.
Source
Thrown at grid/core-impl/src/datagrid/DynamicNestedTable.java:171
@Override
public void addRow(@NotNull GridRow value) {
myRows.add(new Row(value.getRowNum(), GridRow.getValues(value)));
}
@Override
public void removeRow(int rowIdx) {
myRows.remove(rowIdx);
}
@Override
public int getRowNum(int modelRowIdx) {
return myRows.get(modelRowIdx).rowNum;
}
@Override
public void insertRows(int startingIdx, List<GridRow> rows) {
if (startingIdx > getRowsNum()) {
throw new IllegalArgumentException(
"Starting index " +
startingIdx +
" is greater than the total number of rows " +
getRowsNum() +
". Starting index should be less or equal to " +
getRowsNum()
);
}
// Correctly replace existing rows with new rows from the list
int endIndex = min(startingIdx + rows.size(), getRowsNum());
for (int i = startingIdx; i < endIndex; ++i) {
setRow(i, rows.get(i - startingIdx)); // Use (i - startingIdx) to correctly index into 'rows'
}
// Add any remaining new rows beyond the existing table size
if (rows.size() > getRowsNum() - startingIdx) {
for (int i = endIndex; i < startingIdx + rows.size(); ++i) {View on GitHub (pinned to be881553f2)
Solutions
- Clamp: use Math.min(startingIdx, table.getRowsNum()) when appending at the end is the intended semantics.
- Recompute startingIdx from the live row count immediately before each insertRows call.
- Insert blocks in descending original-index order so earlier inserts do not shift later positions.
Example fix
// before table.insertRows(startingIdx, rows); // after int safeIdx = Math.min(startingIdx, table.getRowsNum()); table.insertRows(safeIdx, rows);
Defensive patterns
Strategy: validation
Validate before calling
int safeIdx = Math.min(startingIdx, table.getRowsNum()); table.insertRows(safeIdx, rows);
Prevention
- Clamp insertion indexes to the live row count.
- When inserting multiple blocks, recompute each block's index after the previous insert.
When it happens
Trigger: Calling insertRows after rows were concurrently removed so that a previously valid startingIdx now exceeds the count; computing the insert position as rowsNum() + offset; passing an already-shifted index after an earlier insert in the same batch.
Common situations: Paste/drag-drop of multiple row blocks where each block's index is precomputed; a table refresh shrinking the row list between index calculation and the insert call.
Related errors
- Invalid given row index: %d. Index should be in range from 0
- "Given column index " + colIdx + " is not valid."
- "Unable to set value. No GridRow found at row index: " + row
- "Given column index " + colIdx + " is not valid."
- Row %d failed: hierarchicalIdx cannot be null
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/675a69a187308cac.
Report an issue: GitHub.