JetBrains/intellij-community · error · IllegalArgumentException

"Given column index " + colIdx + " is not valid."

Error message

"Given column index " + colIdx + " is not valid."

What it means

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.

Source

Thrown at grid/core-impl/src/datagrid/DynamicNestedTable.java:103

  @Override
  public int getColumnsNum() {
    return myColumnsHierarchy.getChildren().size();
  }

  @Override
  public boolean isValidRowIdx(int rowIdx) {
    return rowIdx > -1 && rowIdx < getRowsNum();
  }

  @Override
  public boolean isValidColumnIdx(int colIdx) {
    return colIdx > -1 && colIdx < getColumnsNum();
  }

  @Override
  public int getColumnType(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 getType(merger);
  }

  private @NotNull List<String> getColumnValues(int colIdx) {
    List<String> columnValues = new ArrayList<>();
    for (int i = 0; i < min(200, myRows.size()); ++i) {
      Object value = myRows.get(i).values[colIdx];
      columnValues.add(value == null ? null : value.toString());
    }
    return columnValues;
  }

  @Override

View on GitHub (pinned to be881553f2)

Solutions

  1. Call isValidColumnIdx(colIdx) (or check 0 <= colIdx < getColumnsNum()) before getColumnType.
  2. Re-fetch column indexes after any event that can rebuild the nested table (re-parse, schema change).
  3. If the index originates from a GridColumn, resolve it via the current column list rather than storing an int.

Example fix

// before
int type = table.getColumnType(colIdx);

// after
if (table.isValidColumnIdx(colIdx)) {
  int type = table.getColumnType(colIdx);
}
Defensive patterns

Strategy: validation

Validate before calling

if (colIdx < 0 || colIdx >= table.getColumnsNum()) {
  throw new IllegalStateException("stale column index " + colIdx + ", columns=" + table.getColumnsNum());
}

Try / catch

try { type = table.getColumnType(colIdx); } catch (IllegalArgumentException e) { LOG.warn("column type lookup failed", e); type = -1; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/7e4a7441ad4e5e56. Report an issue: GitHub.