{"record":{"id":"e52f06b11b11637c","repo":"apache/hadoop","slug":"component-type-is-set-as-the-output-type-but-n","errorCode":null,"errorMessage":"Component type {} is set as the output type, but no encoding is implemented for this type.","messagePattern":"Component type (.+?) is set as the output type, but no encoding is implemented for this type\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java","lineNumber":197,"sourceCode":"    // do the inner loop.  Walk the decision tree only once.\n    if (componentType == Boolean.TYPE) {          // boolean\n      writeBooleanArray(out);\n    } else if (componentType == Character.TYPE) { // char\n      writeCharArray(out);\n    } else if (componentType == Byte.TYPE) {      // byte\n      writeByteArray(out);\n    } else if (componentType == Short.TYPE) {     // short\n      writeShortArray(out);\n    } else if (componentType == Integer.TYPE) {   // int\n      writeIntArray(out);\n    } else if (componentType == Long.TYPE) {      // long\n      writeLongArray(out);\n    } else if (componentType == Float.TYPE) {     // float\n      writeFloatArray(out);\n    } else if (componentType == Double.TYPE) {    // double\n      writeDoubleArray(out);\n    } else {\n      throw new IOException(\"Component type \" + componentType.toString()\n          + \" is set as the output type, but no encoding is implemented for this type.\");\n    }\n  }\n\n  /* \n   * @see org.apache.hadoop.io.Writable#readFields(java.io.DataInput)\n   */\n  @Override\n  public void readFields(DataInput in) throws IOException {\n    \n    // read and set the component type of the array\n    @SuppressWarnings(\"deprecation\")\n    String className = UTF8.readString(in);\n    Class<?> componentType = getPrimitiveClass(className);\n    if (componentType == null) {\n      throw new IOException(\"encoded array component type \"\n          + className + \" is not a candidate primitive type\");\n    }","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java#L179-L215","documentation":"write() dispatches on componentType across if/else branches for the eight primitives and throws IOException if none match. Under normal construction this is unreachable, because checkPrimitive() already restricted componentType to PRIMITIVE_NAMES (exactly those eight types). It is a defensive internal-consistency error: it fires only when the class invariant was bypassed — e.g. write() on a fresh no-arg instance would NPE earlier on componentType.getName(), or a subclass/reflection path set componentType without validation.","triggerScenarios":"write() called after componentType was assigned through reflection or an overridden method to something outside the eight primitives; subclass extending ArrayPrimitiveWritable and mutating protected state directly, then serializing.","commonSituations":"Rare in practice; appears when test code or framework plumbing manipulates the writable's internals, or a custom fork added a new component type to PRIMITIVE_NAMES without adding a write branch.","solutions":["Always populate instances via the constructors or set(Object) so checkPrimitive() enforces the invariant.","If you forked/extended the class and added a component type, add the matching writeXxxArray branch.","Audit reflection-based (e.g. serialization frameworks) mutation of the writable's fields."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  w.write(out);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"no encoding is implemented\")) {\n    throw new IllegalStateException(\"ArrayPrimitiveWritable invariant violated; instance built outside constructors/set()\", e);\n  }\n  throw e;\n}","preventionTips":["Only populate the writable through constructors and set().","Never mutate componentType via reflection in tests or frameworks."],"tags":["hadoop","serialization","writable","invariant-violation","defensive-check"],"backgroundTag":"unsupported-type-encoding","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}