{"record":{"id":"f9ad915f4026f975","repo":"apache/iceberg","slug":"cannot-set-value-f9ad91","errorCode":null,"errorMessage":"Cannot set value ","messagePattern":"Cannot set value ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/util/Pair.java","lineNumber":76,"sourceCode":"  private X first;\n  private Y second;\n\n  private Pair(X first, Y second) {\n    this.first = first;\n    this.second = second;\n  }\n\n  @Override\n  @SuppressWarnings(\"unchecked\")\n  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;","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/util/Pair.java#L58-L94","documentation":"Pair.put is a StructLike positional setter that only accepts positions 0 (first) or 1 (second). Passing any other index is an API contract violation, so it throws IllegalArgumentException with the offending index and value.","triggerScenarios":"Calling put(int pos, Object value) on a Pair with pos outside {0,1}, e.g. from generic StructLike code that assumes a different arity.","commonSituations":"Generic structural-copy code iterating over field counts that doesn't match Pair's fixed 2-field schema; reflection-based writers.","solutions":["Only call put with index 0 or 1","Use the first()/second() accessors or the Pair.of factory instead of positional access","Fix the loop bound in generic StructLike handling code to use the record's size"],"exampleFix":"// before\npair.put(2, value); // throws\n// after\npair.put(value instanceof Integer ? 0 : 1, value);","handlingStrategy":"validation","validationCode":"if (pos < 0 || pos > 1) throw new IllegalArgumentException(\"Pair position must be 0 or 1, got \" + pos);","typeGuard":"boolean isValidPairPosition(int i) { return i == 0 || i == 1; }","tryCatchPattern":"try { pair.put(pos, v); } catch (IllegalArgumentException e) { /* log index and fix caller */ }","preventionTips":["Prefer first()/second() over positional access","Use Pair.of(...) factories","Bound generic StructLike loops with the actual schema size"],"tags":["pair","structlike","argument"],"backgroundTag":"invalid-argument-value","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"}