{"record":{"id":"d8f9f6ccfa402288","repo":"apache/iceberg","slug":"not-a-variant-type-this","errorCode":null,"errorMessage":"Not a variant type: + this","messagePattern":"Not a variant type: \\+ this","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/types/Type.java","lineNumber":89,"sourceCode":"\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\n  default boolean isMapType() {\n    return false;\n  }\n","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/types/Type.java#L71-L107","documentation":"Type.asVariantType() narrows a Type to Types.VariantType; the default throws IllegalArgumentException because only VariantType overrides it. Variant is a special nested type, so narrowing fails for every other Type.","triggerScenarios":"Calling asVariantType() on any non-variant Type — typically in generic visitor code (visit) that handles all nested kinds and calls each asXxxType unconditionally.","commonSituations":"Visitor implementations written before the Variant type existed that now encounter variant columns; code inspecting metadata/physics columns where variant type appears unexpectedly; older clients reading tables containing variant columns.","solutions":["Check type.isVariantType() before calling asVariantType().","Update visitors/handlers to support VariantType (requires Iceberg format supporting variants).","Filter variant columns out before generic type processing if unsupported."],"exampleFix":"// before\nTypes.VariantType vt = field.type().asVariantType();\n// after\nif (field.type().isVariantType()) {\n  Types.VariantType vt = Types.VariantType.get();\n}","handlingStrategy":"type-guard","validationCode":"Preconditions.checkArgument(type.isVariantType(), \"Expected variant, got: %s\", type);","typeGuard":"if (type.isVariantType()) {\n  Types.VariantType vt = Types.VariantType.get();\n}","tryCatchPattern":"try {\n  Types.VariantType vt = type.asVariantType();\n} catch (IllegalArgumentException e) {\n  // non-variant path\n}","preventionTips":["Check isVariantType() before narrowing.","Update visitors and type converters to handle VariantType.","Gate variant support on engine/client capability before processing such tables."],"tags":["types","iceberg","variant"],"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"}