apache/iceberg · error · IllegalStateException
Not an instance of
Error message
Not an instance of
What it means
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.
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
Example fix
// before Long ts = record.get(2, Long.class); // stored as Integer // after Integer ts = record.get(2, Integer.class);
Defensive patterns
Strategy: type-guard
Validate before calling
Types.NestedField f = table.schema().columns().get(pos); Class<?> expected = f.type().typeId() == Type.TypeID.LONG ? Long.class : f.type().typeId() == Type.TypeID.INTEGER ? Integer.class : /* ... */ Object.class;
Type guard
<T> T getIfInstance(Record r, int pos, Class<T> c) { Object v = r.get(pos); return c.isInstance(v) ? c.cast(v) : null; } Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot convert date
- Cannot convert dict encoded field
- Cannot convert time
- Cannot convert timestamp
- Cannot convert timestamptz
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/9ff7e1d57d3416cf.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/apache/iceberg/data/GenericRecord.java:138
}
@Override
public int size() {
return size;
}
@Override
public Object get(int pos) {
return values[pos];
}
@Override
public <T> T get(int pos, Class<T> javaClass) {
Object value = get(pos);
if (value == null || javaClass.isInstance(value)) {
return javaClass.cast(value);
} else {
throw new IllegalStateException("Not an instance of " + javaClass.getName() + ": " + value);
}
}
@Override
public <T> void set(int pos, T value) {
values[pos] = value;
}
@Override
public GenericRecord copy() {
return new GenericRecord(this);
}
@Override
public GenericRecord copy(Map<String, Object> overwriteValues) {
return new GenericRecord(this, overwriteValues);
}
View on GitHub (pinned to 86d9c8fc54)