apache/iceberg · error · IllegalArgumentException

Cannot get value

Error message

Cannot get value 

What it means

Pair.get(int) returns the value at positional index 0 (first) or 1 (second); any other index is invalid for a 2-element tuple and throws IllegalArgumentException. It exists so Pair can act as a StructLike.

Source

Thrown at core/src/main/java/org/apache/iceberg/util/Pair.java:86

  public void put(int i, Object v) {
    if (i == 0) {
      this.first = (X) v;
      return;
    } else if (i == 1) {
      this.second = (Y) v;
      return;
    }
    throw new IllegalArgumentException("Cannot set value " + i + " (not 0 or 1): " + v);
  }

  @Override
  public Object get(int i) {
    if (i == 0) {
      return first;
    } else if (i == 1) {
      return second;
    }
    throw new IllegalArgumentException("Cannot get value " + i + " (not 0 or 1)");
  }

  @Override
  public Schema getSchema() {
    if (schema == null) {
      this.schema = SCHEMA_CACHE.get(Pair.of(first.getClass(), second.getClass()));
    }
    return schema;
  }

  public X first() {
    return first;
  }

  public Y second() {
    return second;
  }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Only read positions 0 and 1
  2. Use first()/second() instead of positional get
  3. Correct the arity used in generic StructLike traversal

Example fix

// before
Object v = pair.get(3);
// after
Object v = pair.get(0); // or pair.first()
Defensive patterns

Strategy: type-guard

Validate before calling

if (i < 0 || i > 1) throw new IllegalArgumentException("Pair position must be 0 or 1, got " + i);

Type guard

boolean inPairRange(int i) { return i == 0 || i == 1; }

Try / catch

try { Object v = pair.get(i); } catch (IllegalArgumentException e) { /* clamp index to 0 or 1 */ }

Prevention

When it happens

Trigger: Calling get(i) with i not 0 or 1, typically from generic StructLike iteration code using the wrong field count.

Common situations: Code that computes position from a schema of different arity; reading Pair fields in a loop bounded by a foreign schema size.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/bb245457a8ff3755. Report an issue: GitHub.