apache/hadoop · error · HadoopIllegalArgumentException
null component type not allowed
Error message
null component type not allowed
What it means
ArrayPrimitiveWritable wraps a Java array of primitives (boolean, char, byte, short, int, long, float, double) for Writable serialization. checkPrimitive() rejects a null componentType before the instance can be built. This is thrown when the componentType argument passed to ArrayPrimitiveWritable(Class<?>) is null, since the value-carrying paths (set()) run checkArray() first and never reach here with null.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java:73
new HashMap<String, Class<?>>(16);
static {
PRIMITIVE_NAMES.put(boolean.class.getName(), boolean.class);
PRIMITIVE_NAMES.put(byte.class.getName(), byte.class);
PRIMITIVE_NAMES.put(char.class.getName(), char.class);
PRIMITIVE_NAMES.put(short.class.getName(), short.class);
PRIMITIVE_NAMES.put(int.class.getName(), int.class);
PRIMITIVE_NAMES.put(long.class.getName(), long.class);
PRIMITIVE_NAMES.put(float.class.getName(), float.class);
PRIMITIVE_NAMES.put(double.class.getName(), double.class);
}
private static Class<?> getPrimitiveClass(String className) {
return PRIMITIVE_NAMES.get(className);
}
private static void checkPrimitive(Class<?> componentType) {
if (componentType == null) {
throw new HadoopIllegalArgumentException("null component type not allowed");
}
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) { View on GitHub (pinned to 2add963021)
Solutions
- Pass one of the eight primitive TYPE constants (Integer.TYPE, Long.TYPE, Boolean.TYPE, Character.TYPE, Byte.TYPE, Short.TYPE, Float.TYPE, Double.TYPE) instead of null.
- If the Class comes from a lookup, null-check it before constructing and fail with your own descriptive error naming the offending input.
- Use the no-arg ArrayPrimitiveWritable() plus set(Object) if you only have a value, so the component type is derived from a real array.
Example fix
// before
Class<?> t = PRIMITIVES.get(configuredType); // may be null
new ArrayPrimitiveWritable(t);
// after
Class<?> t = PRIMITIVES.get(configuredType);
if (t == null) {
throw new IllegalArgumentException("Unknown primitive type: " + configuredType);
}
new ArrayPrimitiveWritable(t); Defensive patterns
Strategy: validation
Validate before calling
Class<?> t = resolveComponentType(cfg);
if (t == null || !t.isPrimitive()) {
throw new IllegalArgumentException("Component type must be a primitive, got: " + cfg);
} Prevention
- Never pass a Class obtained from a map lookup or Class.forName without a null check.
- Centralize the list of supported primitives in one constant used by both validation and construction.
When it happens
Trigger: Calling new ArrayPrimitiveWritable((Class<?>) null) — the constructor at line 113 passes the argument straight into checkPrimitive(). Also any subclass or reflection-based call that supplies a null Class to this constructor.
Common situations: Programmatically building a component type from configuration or a schema (e.g. Class.forName(userType) returning null being swallowed, or a map lookup miss) and passing the result into the typed constructor.
Related errors
- null value 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/15ed209501b6b593.
Report an issue: GitHub.