{"record":{"id":"c6418f41a04ec8b5","repo":"apache/iceberg","slug":"not-an-array","errorCode":null,"errorMessage":"Not an array: ","messagePattern":"Not an array: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/variants/VariantValue.java","lineNumber":60,"sourceCode":"    throw new IllegalArgumentException(\"Not a primitive: \" + this);\n  }\n\n  /**\n   * Returns this value as a {@link VariantObject}.\n   *\n   * @throws IllegalArgumentException if the value is not an object\n   */\n  default VariantObject asObject() {\n    throw new IllegalArgumentException(\"Not an object: \" + this);\n  }\n\n  /**\n   * Returns this value as a {@link VariantArray}.\n   *\n   * @throws IllegalArgumentException if the value is not an array\n   */\n  default VariantArray asArray() {\n    throw new IllegalArgumentException(\"Not an array: \" + this);\n  }\n\n  static VariantValue from(VariantMetadata metadata, ByteBuffer value) {\n    return VariantUtil.fromBuffer(metadata, value, 0);\n  }\n}\n","sourceCodeStart":42,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/variants/VariantValue.java#L42-L67","documentation":"VariantValue.asArray() is a default downcast helper; the interface implementation always throws this IllegalArgumentException because only VariantArray instances are arrays. The caller assumed an array value but the variant is a primitive or object.","triggerScenarios":"Calling asArray() on a VariantValue that is not a VariantArray — e.g. cursor()/array element traversal over an object or primitive, or expectedArray validation on mismatched data.","commonSituations":"Assuming a variant holds a list when it holds a scalar; data shape changed between writer versions; missing is-array check before iterating elements.","solutions":["Verify the value's basic type is ARRAY (or use instanceof VariantArray) before calling asArray()","Handle primitive/object values explicitly in the caller","Catch IllegalArgumentException and branch on the actual type"],"exampleFix":"// before\nVariantArray arr = value.asArray();\n// after\nif (value instanceof VariantArray) {\n  VariantArray arr = (VariantArray) value;\n} else {\n  throw new IllegalStateException(\"expected array, got \" + value.type());\n}","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof VariantArray)) {\n  throw new IllegalStateException(\"expected array variant, got \" + value.type());\n}","typeGuard":"if (value instanceof VariantArray) { VariantArray a = (VariantArray) value; }","tryCatchPattern":"try {\n  VariantArray a = value.asArray();\n} catch (IllegalArgumentException e) {\n  // handle primitive/object case\n}","preventionTips":["Check the basic type is ARRAY before iterating elements","Expect shape drift between writer versions and branch on type","Prefer instanceof narrowing over default downcast helpers"],"tags":["variants","type-cast","downcast"],"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"}