apache/hadoop · error · RuntimeException
The type of instance is: " + instance.getClass() + ", which
Error message
The type of instance is: " + instance.getClass() + ", which is NOT registered.
What it means
GenericWritable serializes one of a fixed set of Writable types, identified by an index into the array returned by the subclass's getTypes(). set(Writable) scans that array for the instance's exact class and throws RuntimeException when it is absent — there is no type byte that could encode an unregistered class, and readFields() on the other end would not know how to reconstruct it.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/GenericWritable.java:106
private Configuration conf = null;
/**
* Set the instance that is wrapped.
*
* @param obj input obj.
*/
public void set(Writable obj) {
instance = obj;
Class<? extends Writable> instanceClazz = instance.getClass();
Class<? extends Writable>[] clazzes = getTypes();
for (int i = 0; i < clazzes.length; i++) {
Class<? extends Writable> clazz = clazzes[i];
if (clazz.equals(instanceClazz)) {
type = (byte) i;
return;
}
}
throw new RuntimeException("The type of instance is: "
+ instance.getClass() + ", which is NOT registered.");
}
/**
* Return the wrapped instance.
* @return the wrapped instance.
*/
public Writable get() {
return instance;
}
@Override
public String toString() {
return "GW[" + (instance != null ? ("class=" + instance.getClass().getName() +
",value=" + instance.toString()) : "(null)") + "]";
}
@OverrideView on GitHub (pinned to 2add963021)
Solutions
- Append the missing class to the subclass's getTypes() array (append at the end to keep existing indexes stable for old data).
- Ensure the exact runtime class is registered — register the concrete subclass, not just its superclass.
- Never reorder getTypes(); index positions are the wire format.
Example fix
// before
class MyGeneric extends GenericWritable {
protected Class<? extends Writable>[] getTypes() {
return new Class[] { IntWritable.class };
}
}
myGeneric.set(new Text("x")); // throws
// after
class MyGeneric extends GenericWritable {
protected Class<? extends Writable>[] getTypes() {
return new Class[] { IntWritable.class, Text.class }; // appended, order stable
}
} Defensive patterns
Strategy: validation
Validate before calling
Class<? extends Writable> c = candidate.getClass();
boolean registered = Arrays.asList(getTypes()).contains(c);
if (!registered) {
throw new IllegalArgumentException(c.getName() + " not in getTypes(); append it at the end");
}
gw.set(candidate); Prevention
- Register the exact concrete class; matching is equals-based, not instanceof.
- Append new types to getTypes() — never reorder or remove — because indexes are the wire format.
When it happens
Trigger: myGeneric.set(new Text("x")) when getTypes() returns only {IntWritable.class, LongWritable.class}; adding a new Writable subtype to the data model but forgetting to append it to getTypes(); passing a subclass (e.g. MyText extends Text) whose exact class differs from the registered one — matching is clazz.equals(instanceClazz), not instanceof.
Common situations: Evolving a polymorphic field (e.g. a value column that can hold several writable types) across job versions; wrapping user subclasses where equals-based matching misses because the class is a subtype of the registered class.
Related errors
- Exception while get content summary
- f.toString()
- Class {} already registered but maps to {} and not {}
- Id {} exists but maps to {} and not {}
- adding an additional class would exceed the maximum number a
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/b424af7dae948f6c.
Report an issue: GitHub.