{"record":{"id":"7e4a7441ad4e5e56","repo":"JetBrains/intellij-community","slug":"given-column-index-colidx-is-not-valid","errorCode":null,"errorMessage":"\"Given column index \" + colIdx + \" is not valid.\"","messagePattern":"\"Given column index \" \\+ colIdx \\+ \" is not valid\\.\"","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"grid/core-impl/src/datagrid/DynamicNestedTable.java","lineNumber":103,"sourceCode":"  @Override\n  public int getColumnsNum() {\n    return myColumnsHierarchy.getChildren().size();\n  }\n\n  @Override\n  public boolean isValidRowIdx(int rowIdx) {\n    return rowIdx > -1 && rowIdx < getRowsNum();\n  }\n\n  @Override\n  public boolean isValidColumnIdx(int colIdx) {\n    return colIdx > -1 && colIdx < getColumnsNum();\n  }\n\n  @Override\n  public int getColumnType(int colIdx) {\n    if (!isValidColumnIdx(colIdx)) {\n      throw new IllegalArgumentException(\"Given column index \" + colIdx + \" is not valid.\");\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 getType(merger);\n  }\n\n  private @NotNull List<String> getColumnValues(int colIdx) {\n    List<String> columnValues = new ArrayList<>();\n    for (int i = 0; i < min(200, myRows.size()); ++i) {\n      Object value = myRows.get(i).values[colIdx];\n      columnValues.add(value == null ? null : value.toString());\n    }\n    return columnValues;\n  }\n\n  @Override","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/grid/core-impl/src/datagrid/DynamicNestedTable.java#L85-L121","documentation":"DynamicNestedTable.getColumnType(int) throws IllegalArgumentException when colIdx is negative or >= getColumnsNum(). The guard isValidColumnIdx bounds-checks the index against the nested table's column hierarchy before the type-merger sniffing of the first 200 rows runs.","triggerScenarios":"Calling getColumnType on a DynamicNestedTable built from CSV-imported data with a stale column index — e.g. after columns were removed or the source re-parsed with fewer columns, or when passing a view-row/column index where a nested-table index was expected.","commonSituations":"UI code caching a column index across a model refresh; desynchronized column count between the grid view model and the nested table; off-by-one from using column count as the last index.","solutions":["Call isValidColumnIdx(colIdx) (or check 0 <= colIdx < getColumnsNum()) before getColumnType.","Re-fetch column indexes after any event that can rebuild the nested table (re-parse, schema change).","If the index originates from a GridColumn, resolve it via the current column list rather than storing an int."],"exampleFix":"// before\nint type = table.getColumnType(colIdx);\n\n// after\nif (table.isValidColumnIdx(colIdx)) {\n  int type = table.getColumnType(colIdx);\n}","handlingStrategy":"validation","validationCode":"if (colIdx < 0 || colIdx >= table.getColumnsNum()) {\n  throw new IllegalStateException(\"stale column index \" + colIdx + \", columns=\" + table.getColumnsNum());\n}","typeGuard":null,"tryCatchPattern":"try { type = table.getColumnType(colIdx); } catch (IllegalArgumentException e) { LOG.warn(\"column type lookup failed\", e); type = -1; }","preventionTips":["Always call isValidColumnIdx before any column-indexed accessor.","Drop cached column indexes when the table is rebuilt.","Iterate with i < getColumnsNum(), never <=."],"tags":["datagrid","nested-table","index-validation","csv"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}