{"record":{"id":"e8a1ad5aec9898c0","repo":"apache/iceberg","slug":"can-t-retrieve-values-from-an-empty-struct","errorCode":null,"errorMessage":"Can't retrieve values from an empty struct","messagePattern":"Can't retrieve values from an empty struct","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/EmptyStructLike.java","lineNumber":40,"sourceCode":"\nclass EmptyStructLike implements StructLike, Serializable {\n\n  private static final EmptyStructLike INSTANCE = new EmptyStructLike();\n\n  private EmptyStructLike() {}\n\n  static EmptyStructLike get() {\n    return INSTANCE;\n  }\n\n  @Override\n  public int size() {\n    return 0;\n  }\n\n  @Override\n  public <T> T get(int pos, Class<T> javaClass) {\n    throw new UnsupportedOperationException(\"Can't retrieve values from an empty struct\");\n  }\n\n  @Override\n  public <T> void set(int pos, T value) {\n    throw new UnsupportedOperationException(\"Can't modify an empty struct\");\n  }\n\n  @Override\n  public boolean equals(Object other) {\n    if (this == other) {\n      return true;\n    }\n\n    return other != null && getClass() == other.getClass();\n  }\n\n  @Override\n  public int hashCode() {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/EmptyStructLike.java#L22-L58","documentation":"EmptyStructLike is a StructLike representing a struct with zero fields (used for unpartitioned rows). This library throws UnsupportedOperationException from get() because there are no positions to read from; any positional access is by definition a caller bug.","triggerScenarios":"Calling get(pos, javaClass) on the EmptyStructLike instance, typically obtained via partition-type.toStructLike(...) or internal code accessing the partition struct of an unpartitioned table with pos >= 0.","commonSituations":"Custom scan/delete code that assumes a non-empty partition struct; iterating partition positions of a table created with PartitionSpec.unpartitioned(); generic StructLike projection code reused across partitioned and unpartitioned tables.","solutions":["Check the partition type/spec field count before accessing positions; skip position access when the struct has 0 fields","Use the shared EMPTY instance only as a placeholder, never iterate its positions","If representing an actually-partitioned row, ensure the correct StructLike implementation (e.g. InternalRecordWrapper/Partitioning.partitionType based) is used instead of EmptyStructLike"],"exampleFix":"// before\nObject value = partition.get(0, Object.class);\n// after\nif (spec.partitionType().fields().isEmpty()) {\n  return; // unpartitioned: no partition values to read\n}\nObject value = partition.get(0, Object.class);","handlingStrategy":"type-guard","validationCode":"if (spec.partitionType().fields().isEmpty()) { /* skip positional access */ }","typeGuard":"boolean isReadable(StructLike s, int pos) {\n  return !(s instanceof EmptyStructLike) && pos >= 0;\n}","tryCatchPattern":"try {\n  value = structLike.get(pos, javaClass);\n} catch (UnsupportedOperationException e) {\n  value = null; // empty struct: no partition values\n}","preventionTips":["Check partitionType().fields().isEmpty() before positional StructLike access","Never iterate positions of EmptyStructLike","Use spec.isUnpartitioned() to branch logic early"],"tags":["java","structlike","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}