apache/flink · error · FlinkRuntimeException
Cannot extract TypeInformation from Class alone, because gen
Error message
Cannot extract TypeInformation from Class alone, because generic parameters are missing. Please use TypeInformation.of(TypeHint) instead, or another equivalent method in the API that accepts a TypeHint instead of a Class. For example for a Tuple2<Long, String> pass a 'new TypeHint<Tuple2<Long, String>>(){}'. What it means
TypeInformation.of(Class<T>) delegates to TypeExtractor.createTypeInfo(typeClass), which only succeeds for non-generic types. If the class has generic parameters (e.g., Tuple2.class, List.class, Map.class, or a generic POJO), TypeExtractor throws InvalidTypesException, which is wrapped as a FlinkRuntimeException directing you to the TypeHint-based overload TypeInformation.of(TypeHint).
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/typeinfo/TypeInformation.java:212
public abstract boolean canEqual(Object obj);
// ------------------------------------------------------------------------
/**
* Creates a TypeInformation for the type described by the given class.
*
* <p>This method only works for non-generic types. For generic types, use the {@link
* #of(TypeHint)} method.
*
* @param typeClass The class of the type.
* @param <T> The generic type.
* @return The TypeInformation object for the type described by the hint.
*/
public static <T> TypeInformation<T> of(Class<T> typeClass) {
try {
return TypeExtractor.createTypeInfo(typeClass);
} catch (InvalidTypesException e) {
throw new FlinkRuntimeException(
"Cannot extract TypeInformation from Class alone, because generic parameters are missing. "
+ "Please use TypeInformation.of(TypeHint) instead, or another equivalent method in the API that "
+ "accepts a TypeHint instead of a Class. "
+ "For example for a Tuple2<Long, String> pass a 'new TypeHint<Tuple2<Long, String>>(){}'.");
}
}
/**
* Creates a TypeInformation for a generic type via a utility "type hint". This method can be
* used as follows:
*
* <pre>{@code
* TypeInformation<Tuple2<String, Long>> info = TypeInformation.of(new TypeHint<Tuple2<String, Long>>(){});
* }</pre>
*
* @param typeHint The hint for the generic type.
* @param <T> The generic type.
* @return The TypeInformation object for the type described by the hint.View on GitHub (pinned to 2f3c205e92)
Solutions
- Use TypeInformation.of(new TypeHint<Tuple2<Long,String>>(){}) with fully specified type arguments.
- If you only have a java.lang.reflect.Type (ParameterizedType), use TypeExtractor.createTypeInfo(Type, ...) or build the TypeInformation from the TypeHint at a concrete call site.
- For non-generic types, TypeInformation.of(Class) works as-is — only switch when the type is parameterized.
Example fix
// before
TypeInformation.of(Tuple2.class); // throws: generic params missing
// after
TypeInformation.of(new TypeHint<Tuple2<Long,String>>(){}); Defensive patterns
Strategy: type-guard
Validate before calling
Class<?> c = ...;
if (c.getTypeParameters().length > 0) {
throw new IllegalArgumentException(
"Use TypeInformation.of(TypeHint) for generic type " + c.getName());
}
TypeInformation<?> ti = TypeInformation.of(c); Type guard
static boolean isNonGeneric(Class<?> c) {
return c.getTypeParameters().length == 0;
} Try / catch
try {
return TypeInformation.of(typeClass);
} catch (FlinkRuntimeException e) {
throw new IllegalArgumentException(
"Generic type " + typeClass + " requires a TypeHint", e);
} Prevention
- Use TypeInformation.of(TypeHint) whenever the type has generic parameters.
- Check Class.getTypeParameters().length before using the Class overload.
- Prefer TypeExtractor.createTypeInfo for reflective/generic dispatch.
When it happens
Trigger: Calling TypeInformation.of(Tuple2.class), TypeInformation.of(List.class), or TypeInformation.of(SomeGenericClass.class); passing a raw generic class where the parameters are erased.
Common situations: Building TypeInformation from a Class object obtained reflectively (e.g., from a field or method return type) that turns out to be generic; refactoring from a concrete type to a generic one without switching to TypeHint; serializing generic collections.
Related errors
- The TypeHint is using a generic variable.This is not support
- The implementation of AbstractDeserializationSchema is using
- Could not create the type information for '{}'. The most com
- Could not create the type information for '{}'. The most com
- TypeInformation cannot be filled in for the type after it ha
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/1a1f862c69e8b59c.
Report an issue: GitHub.