{"record":{"id":"3d63d36c8dfeef5a","repo":"apache/iceberg","slug":"not-a-map-type-this","errorCode":null,"errorMessage":"Not a map type: + this","messagePattern":"Not a map type: \\+ this","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/types/Type.java","lineNumber":85,"sourceCode":"\n  default boolean isPrimitiveType() {\n    return false;\n  }\n\n  default PrimitiveType asPrimitiveType() {\n    throw new IllegalArgumentException(\"Not a primitive type: \" + this);\n  }\n\n  default Types.StructType asStructType() {\n    throw new IllegalArgumentException(\"Not a struct type: \" + this);\n  }\n\n  default Types.ListType asListType() {\n    throw new IllegalArgumentException(\"Not a list type: \" + this);\n  }\n\n  default Types.MapType asMapType() {\n    throw new IllegalArgumentException(\"Not a map type: \" + this);\n  }\n\n  default Types.VariantType asVariantType() {\n    throw new IllegalArgumentException(\"Not a variant type: \" + this);\n  }\n\n  default boolean isNestedType() {\n    return false;\n  }\n\n  default boolean isStructType() {\n    return false;\n  }\n\n  default boolean isListType() {\n    return false;\n  }\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/types/Type.java#L67-L103","documentation":"Default guard on Type.asMapType: the receiver is not a Types.MapType, so the cast-style conversion is refused. The concatenated 'this' in the message is the actual type. It fires when code assumes a map type without checking typeId()/isMapType() first — the fault is the unguarded downcast on the caller's side.","triggerScenarios":"Calling asMapType() on struct, list, primitive, or variant types — e.g. via mapType/keyType/valueType helpers or map partner lookups in TypeUtil visitor plumbing when the field type is not a map.","commonSituations":"Reading key/value nested IDs for a column that is actually a list or struct; generic column-pruning code assuming map semantics; engine type conversion that mapped a map column to the wrong Iceberg type.","solutions":["Check type.isMapType() or instanceof Types.MapType before narrowing.","Dispatch with a TypeVisitor instead of chained asXxxType calls.","Verify the schema/field reference actually points to the map type."],"exampleFix":"// before\nTypes.MapType mt = field.type().asMapType();\n// after\nif (field.type() instanceof Types.MapType) {\n  Types.MapType mt = (Types.MapType) field.type();\n}","handlingStrategy":"type-guard","validationCode":"Preconditions.checkArgument(type.isMapType(), \"Expected map, got: %s\", type);","typeGuard":"if (type instanceof Types.MapType) {\n  Types.MapType mt = (Types.MapType) type;\n}","tryCatchPattern":"try {\n  Types.MapType mt = type.asMapType();\n} catch (IllegalArgumentException e) {\n  // non-map path\n}","preventionTips":["Check isMapType() before key/value access.","Branch per type kind in generic schema walkers.","Validate engine-to-Iceberg type mapping for map columns."],"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"}