apache/hadoop · error · IOException
Component type {} is set as the output type, but no encoding
Error message
Component type {} is set as the output type, but no encoding is implemented for this type. What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayPrimitiveWritable.java:197
// do the inner loop. Walk the decision tree only once.
if (componentType == Boolean.TYPE) { // boolean
writeBooleanArray(out);
} else if (componentType == Character.TYPE) { // char
writeCharArray(out);
} else if (componentType == Byte.TYPE) { // byte
writeByteArray(out);
} else if (componentType == Short.TYPE) { // short
writeShortArray(out);
} else if (componentType == Integer.TYPE) { // int
writeIntArray(out);
} else if (componentType == Long.TYPE) { // long
writeLongArray(out);
} else if (componentType == Float.TYPE) { // float
writeFloatArray(out);
} else if (componentType == Double.TYPE) { // double
writeDoubleArray(out);
} else {
throw new IOException("Component type " + componentType.toString()
+ " is set as the output type, but no encoding is implemented for this type.");
}
}
/*
* @see org.apache.hadoop.io.Writable#readFields(java.io.DataInput)
*/
@Override
public void readFields(DataInput in) throws IOException {
// read and set the component type of the array
@SuppressWarnings("deprecation")
String className = UTF8.readString(in);
Class<?> componentType = getPrimitiveClass(className);
if (componentType == null) {
throw new IOException("encoded array component type "
+ className + " is not a candidate primitive type");
}View on GitHub (pinned to 2add963021)
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.
Defensive patterns
Strategy: validation
Try / catch
try {
w.write(out);
} catch (IOException e) {
if (e.getMessage() != null && e.getMessage().contains("no encoding is implemented")) {
throw new IllegalStateException("ArrayPrimitiveWritable invariant violated; instance built outside constructors/set()", e);
}
throw e;
} Prevention
- Only populate the writable through constructors and set().
- Never mutate componentType via reflection in tests or frameworks.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Encoded type {} converted to valid component type {} but no
- Exception while get content summary
- f.toString()
- Class {} already registered but maps to {} and not {}
- Id {} exists but maps to {} and not {}
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/e52f06b11b11637c.
Report an issue: GitHub.