apache/flink · error · IndexOutOfBoundsException

{pos}

Error message

{pos}

What it means

Tuple9.getField(int pos) throws IndexOutOfBoundsException when pos is outside 0..8. Tuple9 is the maximum tuple arity in Flink's Java tuple API, so any ninth-or-higher 0-based index (or a 1-based index of 9) is invalid. The message is the offending position.

Source

Thrown at flink-core-api/src/main/java/org/apache/flink/api/java/tuple/Tuple9.java:145

                return (T) this.f0;
            case 1:
                return (T) this.f1;
            case 2:
                return (T) this.f2;
            case 3:
                return (T) this.f3;
            case 4:
                return (T) this.f4;
            case 5:
                return (T) this.f5;
            case 6:
                return (T) this.f6;
            case 7:
                return (T) this.f7;
            case 8:
                return (T) this.f8;
            default:
                throw new IndexOutOfBoundsException(String.valueOf(pos));
        }
    }

    @Override
    @SuppressWarnings("unchecked")
    public <T> void setField(T value, int pos) {
        switch (pos) {
            case 0:
                this.f0 = (T0) value;
                break;
            case 1:
                this.f1 = (T1) value;
                break;
            case 2:
                this.f2 = (T2) value;
                break;
            case 3:
                this.f3 = (T3) value;

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Use positions 0..8 for Tuple9.getField
  2. Convert 1-based external indices with `pos - 1` and validate the range
  3. If you need more than 9 fields, use a POJO, case class, or Row instead of tuples
  4. Bounds-check against getArity() before access

Example fix

// before (oneBasedColumn comes from a 1-based spec)
Object v = tuple9.getField(oneBasedColumn);

// after
int pos = oneBasedColumn - 1;
Object v = (pos >= 0 && pos < tuple9.getArity()) ? tuple9.getField(pos) : null;
Defensive patterns

Strategy: validation

Validate before calling

int pos = oneBasedIndex - 1; // external specs are often 1-based
if (pos < 0 || pos >= tuple9.getArity()) {
    throw new IllegalArgumentException("Field " + oneBasedIndex + " outside Tuple9");
}
Object v = tuple9.getField(pos);

Try / catch

catch (IndexOutOfBoundsException e) { /* identify whether a 1-based index leaked through and rethrow */ }

Prevention

When it happens

Trigger: getField(9) or a negative index; treating 1-based field numbers (1..9) as 0-based positions; positional loops bounded by another type's arity.

Common situations: External schemas with 1-based column numbers; records that outgrew the 9-field tuple limit while positional access code stayed unchanged.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/4013f3a339339d87. Report an issue: GitHub.