apache/flink · error · IndexOutOfBoundsException

{pos}

Error message

{pos}

What it means

Tuple8.getField(int pos) throws IndexOutOfBoundsException when pos is outside 0..7. Tuple8 is the largest Java tuple arity Flink ships, so code that assumed a bigger tuple fails here first. The message is the invalid position.

Source

Thrown at flink-core-api/src/main/java/org/apache/flink/api/java/tuple/Tuple8.java:137

        switch (pos) {
            case 0:
                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;
            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..7 for Tuple8.getField
  2. If you need more than 8 fields, switch to Tuple9, a POJO, or a Row instead of indexing past the arity
  3. Bounds-check with tuple.getArity() before positional access
  4. Access typed fields (tuple.f0..tuple.f7) directly when the position is static

Example fix

// before
Object v = tuple8.getField(8);

// after
Object v = (pos >= 0 && pos < tuple8.getArity()) ? tuple8.getField(pos) : null;
Defensive patterns

Strategy: validation

Validate before calling

if (pos < 0 || pos >= tuple8.getArity()) {
    throw new IllegalArgumentException("pos " + pos + " outside Tuple8 arity 8");
}
Object v = tuple8.getField(pos);

Try / catch

catch (IndexOutOfBoundsException e) { /* pos in message; rethrow with the projection/schema it came from */ }

Prevention

When it happens

Trigger: getField(8) or a negative index; widening a schema past eight fields but still using Tuple8 with unclamped positions; 1-based indices passed as 0-based.

Common situations: A record type grows to 9+ fields while positional access code still assumes 8 is valid; projection lists reused across tuple sizes; off-by-one iteration.

Related errors


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