{"record":{"id":"05a0879903e4cd22","repo":"apache/iceberg","slug":"not-an-object","errorCode":null,"errorMessage":"Not an object: ","messagePattern":"Not an object: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/variants/VariantValue.java","lineNumber":51,"sourceCode":"   */\n  int writeTo(ByteBuffer buffer, int offset);\n\n  /**\n   * Returns this value as a {@link VariantPrimitive}.\n   *\n   * @throws IllegalArgumentException if the value is not a primitive\n   */\n  default VariantPrimitive<?> asPrimitive() {\n    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":33,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/variants/VariantValue.java#L33-L67","documentation":"VariantValue.asObject() is a default downcast helper; the interface implementation always throws this IllegalArgumentException because only VariantObject instances are objects. The caller assumed an object value but the variant is a primitive or array.","triggerScenarios":"Calling asObject() on a VariantValue that is not a VariantObject — e.g. iterating object fields with cursor()/obj() against an array or primitive, or expectedObject validation failing on actual data.","commonSituations":"Assuming nested variant data is an object when it is an array; data drift where the stored shape changed; missing type check before traversal.","solutions":["Verify the value's basic type is OBJECT (or use instanceof VariantObject) before calling asObject()","Handle primitive/array values explicitly","Catch IllegalArgumentException and branch on the actual type"],"exampleFix":"// before\nVariantObject obj = value.asObject();\n// after\nif (value instanceof VariantObject) {\n  VariantObject obj = (VariantObject) value;\n} else {\n  throw new IllegalStateException(\"expected object, got \" + value.type());\n}","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof VariantObject)) {\n  throw new IllegalStateException(\"expected object variant, got \" + value.type());\n}","typeGuard":"if (value instanceof VariantObject) { VariantObject o = (VariantObject) value; }","tryCatchPattern":"try {\n  VariantObject o = value.asObject();\n} catch (IllegalArgumentException e) {\n  // handle primitive/array case\n}","preventionTips":["Check the basic type is OBJECT before field traversal","Handle polymorphic variant values explicitly","Use instanceof instead of blind downcasts"],"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"}