apache/flink · error · RuntimeException
Could not create the type information for '{}'. The most com
Error message
Could not create the type information for '{}'. The most common reason is failure to infer the generic type information, due to Java's type erasure. In that case, please pass a 'TypeHint' instead of a class to describe the type. For example, to describe 'Tuple2<String, String>' as a generic type, use 'new PravegaDeserializationSchema<>(new TypeHint<Tuple2<String, String>>(){}, serializer);' What it means
StateSerializerReference (v2 support class) constructed with a Class<T> calls TypeExtractor.createTypeInfo(clazz) to derive TypeInformation. If that fails — most commonly because the class carries generic parameters that are erased at runtime — it throws a RuntimeException with guidance to use a TypeHint. This is the v2 analogue of the v1 StateDescriptor type-extraction failure.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/state/v2/StateSerializerReference.java:68
* lazily.
*/
@Nullable private final TypeInformation<T> typeInfo;
public StateSerializerReference(TypeInformation<T> typeInfo) {
super(null);
this.typeInfo = checkNotNull(typeInfo, "type information must not be null");
}
public StateSerializerReference(TypeSerializer<T> typeSerializer) {
super(checkNotNull(typeSerializer, "type serializer must not be null"));
this.typeInfo = null;
}
public StateSerializerReference(Class<T> clazz) {
try {
this.typeInfo = TypeExtractor.createTypeInfo(clazz);
} catch (Exception e) {
throw new RuntimeException(
"Could not create the type information for '"
+ clazz.getName()
+ "'. "
+ "The most common reason is failure to infer the generic type information, due to Java's type erasure. "
+ "In that case, please pass a 'TypeHint' instead of a class to describe the type. "
+ "For example, to describe 'Tuple2<String, String>' as a generic type, use "
+ "'new PravegaDeserializationSchema<>(new TypeHint<Tuple2<String, String>>(){}, serializer);'",
e);
}
}
public TypeInformation<T> getTypeInformation() {
return typeInfo;
}
/**
* Checks whether the serializer has been initialized. Serializer initialization is lazy, to
* allow parametrization of serializers with an {@link ExecutionConfig} via {@linkView on GitHub (pinned to 2f3c205e92)
Solutions
- Use the TypeInformation-based constructor of the v2 descriptor, building TypeInformation via TypeInformation.of(new TypeHint<Tuple2<String,String>>(){}).
- Pass a pre-built TypeSerializer to the StateSerializerReference if you already have one, bypassing extraction.
- For non-generic value types, ensure the class is POJO-compliant (public, no-arg constructor) so createTypeInfo succeeds on the Class path.
Example fix
// before
new ValueStateDescriptor<>("ev", Tuple2.class); // v2 descriptor, erasure
// after
new ValueStateDescriptor<>(
"ev",
TypeInformation.of(new TypeHint<Tuple2<String,String>>(){})); Defensive patterns
Strategy: validation
Validate before calling
Class<?> c = valueClass;
if (c.getTypeParameters().length > 0) {
// use TypeInformation/TypeHint-based ctor instead
TypeInformation<T> ti = TypeInformation.of(new TypeHint<T>(){});
descriptor = new ValueStateDescriptor<>(name, ti);
} Type guard
static boolean isSafeForClassRef(Class<?> c) {
return c.getTypeParameters().length == 0;
} Try / catch
try {
ref = new StateSerializerReference<>(clazz);
} catch (RuntimeException e) {
throw new IllegalArgumentException(
"Provide a TypeInformation or TypeSerializer for " + clazz.getName(), e);
} Prevention
- Prefer StateSerializerReference(TypeInformation) or (TypeSerializer) constructors over the Class one for generic types.
- Verify the class has no type parameters before using the Class path.
- Unit-test v2 descriptor construction for every value type used.
When it happens
Trigger: Building a v2 StateDescriptor or StateSerializerReference with the Class-based constructor where the class is generic (e.g., Tuple2.class, a generic POJO) so TypeExtractor cannot recover type parameters; a class whose type hierarchy contains unresolved type variables.
Common situations: DataStream v2 jobs using MapStateDescriptor(name, Class<UK>, Class<UV>) or ValueStateDescriptor(name, Class<T>) with a generic value type; migrating from v1 and hitting the same erasure wall via the v2 path.
Related errors
- Could not create the type information for '{}'. The most com
- The implementation of AbstractDeserializationSchema is using
- The TypeHint is using a generic variable.This is not support
- Cannot extract TypeInformation from Class alone, because gen
- The given class is no array.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/2d131145b26ee92e.
Report an issue: GitHub.