apache/flink · error · InvalidTypesException
The given class is no subclass of {Writable.class.getName()}
Error message
The given class is no subclass of {Writable.class.getName()} What it means
Thrown by the package-private factory WritableTypeInfo.getWritableTypeInfo(typeClass) when the supplied class is not an assignable subclass of Hadoop's Writable (or is exactly Writable.class). This is a type-extraction-time guard: only concrete Writable subclasses are admissible, and passing anything else raises InvalidTypesException. The message names the expected base class.
Source
Thrown at flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/api/java/typeutils/WritableTypeInfo.java:155
} else {
return false;
}
}
@Override
public boolean canEqual(Object obj) {
return obj instanceof WritableTypeInfo;
}
// --------------------------------------------------------------------------------------------
@PublicEvolving
static <T extends Writable> TypeInformation<T> getWritableTypeInfo(Class<T> typeClass) {
if (Writable.class.isAssignableFrom(typeClass) && !typeClass.equals(Writable.class)) {
return new WritableTypeInfo<T>(typeClass);
} else {
throw new InvalidTypesException(
"The given class is no subclass of " + Writable.class.getName());
}
}
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Make the target class a concrete subclass of org.apache.hadoop.io.Writable (not the raw Writable type).
- Ensure the class passed to WritableTypeInfo/getWritableTypeInfo actually implements Writable.
- If you did not intend a Writable type, use the correct TypeInformation (POJO, generic, tuple) for that class.
- Double-check imports so you pass your Writable subclass, not org.apache.hadoop.io.Writable itself.
Example fix
// before — passing the raw Writable interface TypeInfo.of(org.apache.hadoop.io.Writable.class); // after — pass a concrete Writable subclass TypeInfo.of(MyWritable.class); // where MyWritable implements Writable
Defensive patterns
Strategy: type-guard
Validate before calling
// Before requesting Writable type info, validate the class is a concrete Writable subclass
Class<?> c = candidateClass;
if (!org.apache.hadoop.io.Writable.class.isAssignableFrom(c) || c.equals(org.apache.hadoop.io.Writable.class)) {
throw new IllegalArgumentException(c.getName()
+ " is not a concrete subclass of org.apache.hadoop.io.Writable");
} Type guard
org.apache.hadoop.io.Writable.class.isAssignableFrom(candidateClass) && !candidateClass.equals(org.apache.hadoop.io.Writable.class)
Prevention
- Pass only concrete Writable subclasses to WritableTypeInfo/getWritableTypeInfo.
- Do not pass the raw org.apache.hadoop.io.Writable class.
- Choose the correct TypeInformation (POJO/tuple/generic) for non-Writable classes.
- Verify imports so the subclass, not the base interface, is used.
When it happens
Trigger: Produced when the type extractor resolves a type as a Writable and calls getWritableTypeInfo(typeClass) with a class that is not Writable-assignable or is the raw Writable class itself — e.g. annotating/declaring a type as Writable that is actually a non-Writable class, or requesting Writable type info for Writable.class directly.
Common situations: Declaring a POJO/non-Writable class where a Writable is expected; calling WritableTypeInfo on Writable.class (the base interface, not a subclass); a class that was Writable at build time but no longer is at runtime; misuse of the type-extraction API with a class that fails isAssignableFrom.
Related errors
- InputSplit must implement Writable interface.
- Cannot create Comparator for {typeClass.getCanonicalName()}.
- Hadoop input split must not be null
- Mapper may not be null.
- JobConf may not be null.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/e50f8e95d486cdaa.
Report an issue: GitHub.