{"record":{"id":"61374a520263ea97","repo":"apache/hadoop","slug":"input-array-component-type-is-not-a-candidate-p","errorCode":null,"errorMessage":"input array component type {} is not a candidate primitive type","messagePattern":"input array component type (.+?) is not a candidate primitive type","errorType":"exception","errorClass":"HadoopIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java","lineNumber":76,"sourceCode":"    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) { \n      throw new HadoopIllegalArgumentException(\"null value not allowed\"); \n    }\n    if (! value.getClass().isArray()) {","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java#L58-L94","documentation":"ArrayPrimitiveWritable only supports arrays whose component type is one of the eight Java primitives, verified by lookup in the PRIMITIVE_NAMES map (populated with boolean/char/byte/short/int/long/float/double). checkPrimitive() throws this HadoopIllegalArgumentException when the component type is non-null but its name is not in that map — i.e. it is a reference type or void.","triggerScenarios":"Calling set(new String[n]), set(new Object[n]), set(new Integer[n]) (boxed array), or new ArrayPrimitiveWritable(String[].class). The component type extracted by value.getClass().getComponentType() or passed explicitly is a class, not a primitive TYPE.","commonSituations":"Porting code that boxed primitives (Integer[] instead of int[]) for generics reasons; passing a Writable[] or Text[] assuming ArrayWritable-like behavior; autoboxing collections via toArray() producing Object[] or boxed arrays.","solutions":["Use a primitive array (int[], long[], double[]...) not a boxed or Object array.","For String[] or Writable[] arrays, use org.apache.hadoop.io.ArrayWritable with Text.class or your Writable class instead.","If data arrives boxed, convert once: int[] prim = ArrayUtils.toPrimitive(boxedArray); before wrapping.","For mixed/non-primitive element types, implement a custom Writable."],"exampleFix":"// before\nWritable w = new ArrayPrimitiveWritable(new Integer[] {1, 2, 3}); // throws\n\n// after\nWritable w = new ArrayPrimitiveWritable(new int[] {1, 2, 3});","handlingStrategy":"type-guard","validationCode":"Object v = ...;\nif (v == null || !v.getClass().isArray()\n    || !v.getClass().getComponentType().isPrimitive()) {\n  throw new IllegalArgumentException(\"Value must be a primitive array, got: \" + (v == null ? \"null\" : v.getClass()));\n}","typeGuard":"static boolean isPrimitiveArray(Object v) {\n  return v != null && v.getClass().isArray()\n      && v.getClass().getComponentType().isPrimitive();\n}","tryCatchPattern":null,"preventionTips":["Prefer primitive arrays (int[]) over boxed arrays (Integer[]) throughout MR/serialization code.","For String[]/Writable[] use ArrayWritable, not ArrayPrimitiveWritable."],"tags":["hadoop","serialization","writable","type-validation","primitive-array"],"backgroundTag":"argument-type-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}