JetBrains/intellij-community · error · IllegalArgumentException
Invalid given row index: %d. Index should be in range from 0
Error message
Invalid given row index: %d. Index should be in range from 0 to %d
What it means
DynamicNestedTable.setRow(int, GridRow) throws IllegalArgumentException when rowIdx is not a valid row index (negative or >= myRows.size()). The message states the accepted range 0..rows-1, computed as myRows.size() - 1.
Source
Thrown at grid/core-impl/src/datagrid/DynamicNestedTable.java:146
}
@Override
public String getColumnTypeName(int colIdx) {
if (!isValidColumnIdx(colIdx)) {
throw new IllegalArgumentException("Given column index " + colIdx + " is not valid.");
}
List<String> columnValues = getColumnValues(colIdx);
TypeMerger merger = CsvImportUtil.getPreferredTypeMergerBasedOnContent(
columnValues, STRING_MERGER, INTEGER_MERGER, BIG_INTEGER_MERGER, DOUBLE_MERGER, BOOLEAN_MERGER);
return merger.getName();
}
@Override
public void setRow(int rowIdx, GridRow row) {
if (!isValidRowIdx(rowIdx)) {
throw new IllegalArgumentException(
format("Invalid given row index: %d. Index should be in range from 0 to %d", rowIdx, myRows.size() - 1)
);
}
myRows.set(rowIdx, new Row(row.getRowNum(), GridRow.getValues(row)));
}
@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) {View on GitHub (pinned to be881553f2)
Solutions
- Check isValidRowIdx(rowIdx) before setRow; if the intent is appending, call addRow instead.
- Re-resolve the row index immediately before the write, after any mutation batch completes.
- Wrap batch edit + setRow so no other mutation can interleave (single EDT transaction).
Example fix
// before table.setRow(rowIdx, updatedRow); // rowIdx may be == rowsNum // after if (table.isValidRowIdx(rowIdx)) table.setRow(rowIdx, updatedRow); else table.addRow(updatedRow);
Defensive patterns
Strategy: validation
Validate before calling
if (!table.isValidRowIdx(rowIdx)) {
if (rowIdx == table.getRowsNum()) { table.addRow(row); return; }
throw new IllegalArgumentException("row index " + rowIdx + " out of 0.." + (table.getRowsNum() - 1));
} Prevention
- Compute row indexes immediately before mutation, after pending removals complete.
- Use addRow for append semantics; setRow only replaces existing rows.
When it happens
Trigger: Calling setRow with an index captured before rows were removed, or after sorting/filtering changed the row list, or with rowIdx == getRowsNum() (appending is not supported; use addRow).
Common situations: Editor code writing back an edited row after the model received a removeRows/insertRows batch in between; using a model-row index where the nested table expects its own storage index.
Related errors
- "Given column index " + colIdx + " is not valid."
- "Starting index " + startingIdx + " is greater than the tota
- "Given column index " + colIdx + " is not valid."
- "Unable to set value. No GridRow found at row index: " + row
- Row %d failed: hierarchicalIdx cannot be null
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/a9c2856e0c226993.
Report an issue: GitHub.