{"record":{"id":"15ed209501b6b593","repo":"apache/hadoop","slug":"null-component-type-not-allowed","errorCode":null,"errorMessage":"null component type not allowed","messagePattern":"null component type 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":73,"sourceCode":"    new HashMap<String, Class<?>>(16);\n  static {\n    PRIMITIVE_NAMES.put(boolean.class.getName(), boolean.class);\n    PRIMITIVE_NAMES.put(byte.class.getName(), byte.class);\n    PRIMITIVE_NAMES.put(char.class.getName(), char.class);\n    PRIMITIVE_NAMES.put(short.class.getName(), short.class);\n    PRIMITIVE_NAMES.put(int.class.getName(), int.class);\n    PRIMITIVE_NAMES.put(long.class.getName(), long.class);\n    PRIMITIVE_NAMES.put(float.class.getName(), float.class);\n    PRIMITIVE_NAMES.put(double.class.getName(), double.class);\n  }\n  \n  private static Class<?> getPrimitiveClass(String className) {\n    return PRIMITIVE_NAMES.get(className);\n  }\n  \n  private static void checkPrimitive(Class<?> componentType) {\n    if (componentType == null) { \n      throw new HadoopIllegalArgumentException(\"null component type not allowed\"); \n    }\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) { ","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java#L55-L91","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nClass<?> t = PRIMITIVES.get(configuredType); // may be null\nnew ArrayPrimitiveWritable(t);\n\n// after\nClass<?> t = PRIMITIVES.get(configuredType);\nif (t == null) {\n  throw new IllegalArgumentException(\"Unknown primitive type: \" + configuredType);\n}\nnew ArrayPrimitiveWritable(t);","handlingStrategy":"validation","validationCode":"Class<?> t = resolveComponentType(cfg);\nif (t == null || !t.isPrimitive()) {\n  throw new IllegalArgumentException(\"Component type must be a primitive, got: \" + cfg);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["hadoop","serialization","writable","validation","null-check"],"backgroundTag":"null-argument-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}