apache/hadoop · error · HadoopIllegalArgumentException
null value not allowed
Error message
null value not allowed
What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java:92
}
if (! PRIMITIVE_NAMES.containsKey(componentType.getName())) {
throw new HadoopIllegalArgumentException("input array component type "
+ componentType.getName() + " is not a candidate primitive type");
}
}
private void checkDeclaredComponentType(Class<?> componentType) {
if ((declaredComponentType != null)
&& (componentType != declaredComponentType)) {
throw new HadoopIllegalArgumentException("input array component type "
+ componentType.getName() + " does not match declared type "
+ declaredComponentType.getName());
}
}
private static void checkArray(Object value) {
if (value == null) {
throw new HadoopIllegalArgumentException("null value not allowed");
}
if (! value.getClass().isArray()) {
throw new HadoopIllegalArgumentException("non-array value of class "
+ value.getClass() + " not allowed");
}
}
/**
* Construct an empty instance, for use during Writable read
*/
public ArrayPrimitiveWritable() {
//empty constructor
}
/**
* Construct an instance of known type but no value yet
* for use with type-specific wrapper classes.
*View on GitHub (pinned to 2add963021)
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.
Example fix
// before int[] vals = record.getValues(); // may be null out.write(new ArrayPrimitiveWritable(vals)); // throws when null // after int[] vals = record.getValues(); out.write(new ArrayPrimitiveWritable(vals == null ? new int[0] : vals));
Defensive patterns
Strategy: validation
Validate before calling
int[] vals = source.getValues(); if (vals == null) vals = new int[0]; // or encode nullability separately w.set(vals);
Prevention
- 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.
When it happens
Trigger: new ArrayPrimitiveWritable(null) or writable.set(null) — e.g. a null field read from a POJO/Avro record is handed straight to the wrapper.
Common situations: 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.
Related errors
- null component type not allowed
- null valueClass
- source map cannot be null
- input array component type {} does not match declared type {
- The EnumSet argument is null, or is an empty set but with no
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/0e9e010a43b0ba36.
Report an issue: GitHub.