{"record":{"id":"a9c2856e0c226993","repo":"JetBrains/intellij-community","slug":"invalid-given-row-index-d-index-should-be-in-ra","errorCode":null,"errorMessage":"Invalid given row index: %d. Index should be in range from 0 to %d","messagePattern":"Invalid given row index: (.+?)\\. Index should be in range from 0 to (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"grid/core-impl/src/datagrid/DynamicNestedTable.java","lineNumber":146,"sourceCode":"  }\n\n  @Override\n  public String getColumnTypeName(int colIdx) {\n    if (!isValidColumnIdx(colIdx)) {\n      throw new IllegalArgumentException(\"Given column index \" + colIdx + \" is not valid.\");\n    }\n\n    List<String> columnValues = getColumnValues(colIdx);\n    TypeMerger merger = CsvImportUtil.getPreferredTypeMergerBasedOnContent(\n      columnValues, STRING_MERGER, INTEGER_MERGER, BIG_INTEGER_MERGER, DOUBLE_MERGER, BOOLEAN_MERGER);\n\n    return merger.getName();\n  }\n\n  @Override\n  public void setRow(int rowIdx, GridRow row) {\n    if (!isValidRowIdx(rowIdx)) {\n      throw new IllegalArgumentException(\n        format(\"Invalid given row index: %d. Index should be in range from 0 to %d\", rowIdx, myRows.size() - 1)\n      );\n    }\n    myRows.set(rowIdx, new Row(row.getRowNum(), GridRow.getValues(row)));\n  }\n\n  @Override\n  public void addRow(@NotNull GridRow value) {\n    myRows.add(new Row(value.getRowNum(), GridRow.getValues(value)));\n  }\n\n  @Override\n  public void removeRow(int rowIdx) {\n    myRows.remove(rowIdx);\n  }\n\n  @Override\n  public int getRowNum(int modelRowIdx) {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/grid/core-impl/src/datagrid/DynamicNestedTable.java#L128-L164","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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)."],"exampleFix":"// before\ntable.setRow(rowIdx, updatedRow); // rowIdx may be == rowsNum\n\n// after\nif (table.isValidRowIdx(rowIdx)) table.setRow(rowIdx, updatedRow);\nelse table.addRow(updatedRow);","handlingStrategy":"validation","validationCode":"if (!table.isValidRowIdx(rowIdx)) {\n  if (rowIdx == table.getRowsNum()) { table.addRow(row); return; }\n  throw new IllegalArgumentException(\"row index \" + rowIdx + \" out of 0..\" + (table.getRowsNum() - 1));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute row indexes immediately before mutation, after pending removals complete.","Use addRow for append semantics; setRow only replaces existing rows."],"tags":["datagrid","nested-table","row-mutation","index-validation"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}