{"record":{"id":"25b3bb3954140a04","repo":"apache/iceberg","slug":"not-a-nested-type-this","errorCode":null,"errorMessage":"Not a nested type: + this","messagePattern":"Not a nested type: \\+ this","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/types/Type.java","lineNumber":113,"sourceCode":"\n  default boolean isStructType() {\n    return false;\n  }\n\n  default boolean isListType() {\n    return false;\n  }\n\n  default boolean isMapType() {\n    return false;\n  }\n\n  default boolean isVariantType() {\n    return false;\n  }\n\n  default NestedType asNestedType() {\n    throw new IllegalArgumentException(\"Not a nested type: \" + this);\n  }\n\n  abstract class PrimitiveType implements Type {\n    @Override\n    public boolean isPrimitiveType() {\n      return true;\n    }\n\n    @Override\n    public PrimitiveType asPrimitiveType() {\n      return this;\n    }\n\n    Object writeReplace() throws ObjectStreamException {\n      return new PrimitiveLikeHolder(toString());\n    }\n\n    @Override","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/types/Type.java#L95-L131","documentation":"Type.asNestedType() narrows a Type to the NestedType base class (struct/list/map/variant). The default implementation throws IllegalArgumentException because primitives are not nested. Nested types expose inner fields and IDs; primitives do not.","triggerScenarios":"Calling asNestedType() on a primitive Type — e.g. helpers like struct/list/map/stringType/decimalType or BaseFile code that inspects a partition/source type assuming it is nested.","commonSituations":"Partition handling where a partition field's source is a primitive (identity-partitioned by a primitive column); generic schema traversal that skips the isNestedType check; refactoring that changed a field from struct to primitive.","solutions":["Check type.isNestedType() before calling asNestedType().","Branch on isPrimitiveType() vs isNestedType() in traversal code.","Correct the field/type reference so nested access happens only on struct/list/map/variant types."],"exampleFix":"// before\nTypes.NestedType nested = partitionField.sourceType().asNestedType();\n// after\nType t = partitionField.sourceType();\nTypes.NestedType nested = t.isNestedType() ? (Types.NestedType) t : null;","handlingStrategy":"type-guard","validationCode":"Preconditions.checkArgument(type.isNestedType(), \"Expected nested type, got: %s\", type);","typeGuard":"if (type.isNestedType()) {\n  Types.NestedType nested = (Types.NestedType) type;\n}","tryCatchPattern":"try {\n  Types.NestedType nested = type.asNestedType();\n} catch (IllegalArgumentException e) {\n  // primitive path\n}","preventionTips":["Check isNestedType() before accessing nested fields.","Handle primitive partition sources separately from nested ones.","Use TypeVisitor to avoid blind nested access."],"tags":["types","iceberg","type-mismatch"],"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"}