{"record":{"id":"9ff7e1d57d3416cf","repo":"apache/iceberg","slug":"not-an-instance-of","errorCode":null,"errorMessage":"Not an instance of ","messagePattern":"Not an instance of ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/data/GenericRecord.java","lineNumber":138,"sourceCode":"  }\n\n  @Override\n  public int size() {\n    return size;\n  }\n\n  @Override\n  public Object get(int pos) {\n    return values[pos];\n  }\n\n  @Override\n  public <T> T get(int pos, Class<T> javaClass) {\n    Object value = get(pos);\n    if (value == null || javaClass.isInstance(value)) {\n      return javaClass.cast(value);\n    } else {\n      throw new IllegalStateException(\"Not an instance of \" + javaClass.getName() + \": \" + value);\n    }\n  }\n\n  @Override\n  public <T> void set(int pos, T value) {\n    values[pos] = value;\n  }\n\n  @Override\n  public GenericRecord copy() {\n    return new GenericRecord(this);\n  }\n\n  @Override\n  public GenericRecord copy(Map<String, Object> overwriteValues) {\n    return new GenericRecord(this, overwriteValues);\n  }\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/data/GenericRecord.java#L120-L156","documentation":"GenericRecord.get(pos, javaClass) first fetches the raw value then casts it to the requested Java class; if the stored value is non-null but not an instance of the requested class, this IllegalStateException is thrown with both the class name and the value.","triggerScenarios":"Calling record.get(pos, Long.class) when the value is an Integer, or requesting String for an int field; class-based accessors (e.g. in GenericData readers) assuming a different Java type than stored.","commonSituations":"Java generic-get convenience usage where schema types changed; comparing int vs long conventions between Iceberg and engine data models; code shared across record types.","solutions":["Request the Java class matching the schema field's Iceberg type (Integer for int, Long for long, etc.)","Read the raw value with get(pos) and convert explicitly","Verify the record's schema matches what your accessor code assumes"],"exampleFix":"// before\nLong ts = record.get(2, Long.class); // stored as Integer\n// after\nInteger ts = record.get(2, Integer.class);","handlingStrategy":"type-guard","validationCode":"Types.NestedField f = table.schema().columns().get(pos);\nClass<?> expected = f.type().typeId() == Type.TypeID.LONG ? Long.class : f.type().typeId() == Type.TypeID.INTEGER ? Integer.class : /* ... */ Object.class;","typeGuard":"<T> T getIfInstance(Record r, int pos, Class<T> c) { Object v = r.get(pos); return c.isInstance(v) ? c.cast(v) : null; }","tryCatchPattern":"try { Long v = record.get(pos, Long.class); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Not an instance of\")) { /* request correct class or convert */ } else throw e; }","preventionTips":["Derive the Java class from the Iceberg schema type, not guesswork","Use get(pos) + explicit conversion when types may vary","Pin int vs long conventions early in generic code"],"tags":["generic-record","type-mismatch","cast"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}