{"record":{"id":"bb245457a8ff3755","repo":"apache/iceberg","slug":"cannot-get-value","errorCode":null,"errorMessage":"Cannot get value ","messagePattern":"Cannot get value ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/util/Pair.java","lineNumber":86,"sourceCode":"  public void put(int i, Object v) {\n    if (i == 0) {\n      this.first = (X) v;\n      return;\n    } else if (i == 1) {\n      this.second = (Y) v;\n      return;\n    }\n    throw new IllegalArgumentException(\"Cannot set value \" + i + \" (not 0 or 1): \" + v);\n  }\n\n  @Override\n  public Object get(int i) {\n    if (i == 0) {\n      return first;\n    } else if (i == 1) {\n      return second;\n    }\n    throw new IllegalArgumentException(\"Cannot get value \" + i + \" (not 0 or 1)\");\n  }\n\n  @Override\n  public Schema getSchema() {\n    if (schema == null) {\n      this.schema = SCHEMA_CACHE.get(Pair.of(first.getClass(), second.getClass()));\n    }\n    return schema;\n  }\n\n  public X first() {\n    return first;\n  }\n\n  public Y second() {\n    return second;\n  }\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/util/Pair.java#L68-L104","documentation":"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.","triggerScenarios":"Calling get(i) with i not 0 or 1, typically from generic StructLike iteration code using the wrong field count.","commonSituations":"Code that computes position from a schema of different arity; reading Pair fields in a loop bounded by a foreign schema size.","solutions":["Only read positions 0 and 1","Use first()/second() instead of positional get","Correct the arity used in generic StructLike traversal"],"exampleFix":"// before\nObject v = pair.get(3);\n// after\nObject v = pair.get(0); // or pair.first()","handlingStrategy":"type-guard","validationCode":"if (i < 0 || i > 1) throw new IllegalArgumentException(\"Pair position must be 0 or 1, got \" + i);","typeGuard":"boolean inPairRange(int i) { return i == 0 || i == 1; }","tryCatchPattern":"try { Object v = pair.get(i); } catch (IllegalArgumentException e) { /* clamp index to 0 or 1 */ }","preventionTips":["Use first()/second() accessors","Don't iterate Pair with a foreign schema's field count","Treat Pair strictly as a 2-tuple"],"tags":["pair","structlike","argument"],"backgroundTag":"index-out-of-range","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}