{"record":{"id":"0e9e010a43b0ba36","repo":"apache/hadoop","slug":"null-value-not-allowed","errorCode":null,"errorMessage":"null value not allowed","messagePattern":"null value not allowed","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java","lineNumber":92,"sourceCode":"    }\n    if (! PRIMITIVE_NAMES.containsKey(componentType.getName())) {\n      throw new HadoopIllegalArgumentException(\"input array component type \"\n          + componentType.getName() + \" is not a candidate primitive type\");\n    }\n  }\n  \n  private void checkDeclaredComponentType(Class<?> componentType) {\n    if ((declaredComponentType != null) \n        && (componentType != declaredComponentType)) {\n      throw new HadoopIllegalArgumentException(\"input array component type \"\n          + componentType.getName() + \" does not match declared type \"\n          + declaredComponentType.getName());     \n    }\n  }\n  \n  private static void checkArray(Object value) {\n    if (value == null) { \n      throw new HadoopIllegalArgumentException(\"null value not allowed\"); \n    }\n    if (! value.getClass().isArray()) {\n      throw new HadoopIllegalArgumentException(\"non-array value of class \"\n          + value.getClass() + \" not allowed\");             \n    }\n  }\n  \n  /**\n   * Construct an empty instance, for use during Writable read\n   */\n  public ArrayPrimitiveWritable() {\n    //empty constructor\n  }\n  \n  /**\n   * Construct an instance of known type but no value yet\n   * for use with type-specific wrapper classes.\n   *","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java#L74-L110","documentation":"checkArray() is the first guard inside set(Object) (and therefore the ArrayPrimitiveWritable(Object) constructor). It throws HadoopIllegalArgumentException when the value is null, because there is no array to derive a component type or length from and a null cannot be serialized by this class.","triggerScenarios":"new ArrayPrimitiveWritable(null) or writable.set(null) — e.g. a null field read from a POJO/Avro record is handed straight to the wrapper.","commonSituations":"Mapping nullable columns or optional fields to writables; a map/get returning null for a missing key whose result is wrapped without a null check.","solutions":["Null-check the value before wrapping and either skip the field, write a length -1 marker of your own, or substitute an empty array (new int[0]).","If nullability is part of your schema, use a wrapper like ObjectWritable or encode null separately — ArrayPrimitiveWritable cannot represent null.","Initialize the source (e.g. empty array instead of null) at data-production time."],"exampleFix":"// before\nint[] vals = record.getValues(); // may be null\nout.write(new ArrayPrimitiveWritable(vals)); // throws when null\n\n// after\nint[] vals = record.getValues();\nout.write(new ArrayPrimitiveWritable(vals == null ? new int[0] : vals));","handlingStrategy":"validation","validationCode":"int[] vals = source.getValues();\nif (vals == null) vals = new int[0]; // or encode nullability separately\nw.set(vals);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check nullable fields before wrapping into any Writable.","Decide on one null representation (empty array vs explicit null flag) per schema and apply it consistently."],"tags":["hadoop","serialization","writable","null-check","validation"],"backgroundTag":"null-argument-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}