JetBrains/intellij-community · error · IllegalStateException

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

Error message

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

What it means

StaticNestedTable.getColumnType(colIdx) throws IllegalStateException when colIdx fails isValidColumnIdx (colIdx > -1 && colIdx < getColumnsNum()). Column type is computed via TypeMerger over the rows data, so a valid index is a hard precondition.

Source

Thrown at grid/core-impl/src/datagrid/StaticNestedTable.java:77

  @Override
  public int getColumnsNum() {
    return myRowsValues.length > 0 ? myRowsValues[0].length : 0;
  }

  @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 IllegalStateException("Given column index " + colIdx + " is not valid.");
    }

    TypeMerger merger = determineColumnType(myRowsValues, new int[] { colIdx });
    return DocumentDataHookUp.DataMarkup.getType(merger);
  }

  @Override
  public String getColumnTypeName(int colIdx) {
    if (!isValidColumnIdx(colIdx)) {
      throw new IllegalStateException("Given column index " + colIdx + " is not valid.");
    }

    TypeMerger merger = determineColumnType(myRowsValues, new int[] { colIdx });
    return merger.getName();
  }

  @Override
  public String getColumnName(int colIdx) {

View on GitHub (pinned to be881553f2)

Solutions

  1. Call isValidColumnIdx(colIdx) (or compare against getColumnsNum()) before getColumnType
  2. Derive column indexes from myColumnsHierarchy.getChildren() size / the same snapshot used to build the table
  3. Fix off-by-one in the caller's column loop

Example fix

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

// after
int type = table.isValidColumnIdx(colIdx) ? table.getColumnType(colIdx) : -1;
Defensive patterns

Strategy: validation

Validate before calling

int safeType = table.isValidColumnIdx(colIdx) ? table.getColumnType(colIdx) : -1;

Prevention

When it happens

Trigger: Calling getColumnType(colIdx) with a negative index or an index >= the number of columns in the static nested table (built from myColumnsHierarchy).

Common situations: Caller uses the parent grid's column count instead of the nested table's; column hierarchy built from one dataset but queried with indexes from another; edge case of an empty columns hierarchy.

Related errors


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