apache/flink · error · InvalidTypesException
The types of the interface {} could not be inferred. Support
Error message
The types of the interface {} could not be inferred. Support for synthetic interfaces, lambdas, and generic or raw types is limited at this point What it means
Thrown by `getParameterType` when the extractor cannot find the requested generic parameter position by traversing the class's implemented interfaces and superclass. The method searches `getGenericInterfaces()` and `getGenericSuperclass()` for a parameterized reference to the base class; if none is found, type inference for that interface parameter has failed.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:1428
}
Type[] interfaceTypes = clazz.getGenericInterfaces();
// search in interfaces for base class
for (Type t : interfaceTypes) {
Type parameter = getParameterTypeFromGenericType(baseClass, typeHierarchy, t, pos);
if (parameter != null) {
return parameter;
}
}
// search in superclass for base class
Type t = clazz.getGenericSuperclass();
Type parameter = getParameterTypeFromGenericType(baseClass, typeHierarchy, t, pos);
if (parameter != null) {
return parameter;
}
throw new InvalidTypesException(
"The types of the interface "
+ baseClass.getName()
+ " could not be inferred. "
+ "Support for synthetic interfaces, lambdas, and generic or raw types is limited at this point");
}
private static Type getParameterTypeFromGenericType(
Class<?> baseClass, List<Type> typeHierarchy, Type t, int pos) {
// base class
if (t instanceof ParameterizedType
&& baseClass.equals(((ParameterizedType) t).getRawType())) {
if (typeHierarchy != null) {
typeHierarchy.add(t);
}
ParameterizedType baseClassChild = (ParameterizedType) t;
return baseClassChild.getActualTypeArguments()[pos];
}
// interface that extended base class as class or parameterized typeView on GitHub (pinned to 2f3c205e92)
Solutions
- Always parameterize Flink function interfaces: `implements MapFunction<String, MyEvent>` instead of raw `implements MapFunction`
- For lambdas, ensure the functional interface has a clear generic signature, or use `.returns(...)` to specify the output type
- Avoid deep inheritance hierarchies with raw types between the function and the Flink interface
- Implement ResultTypeQueryable to bypass reflection-based inference entirely
Example fix
// before — raw interface implementation
class MyFunc implements MapFunction {
public Object map(Object value) { ... }
}
// after — parameterized
class MyFunc implements MapFunction<String, MyEvent> {
public MyEvent map(String value) { ... }
} Defensive patterns
Strategy: validation
Validate before calling
// Check that the function class parameterizes the Flink interface
Type[] interfaces = myFunction.getClass().getGenericInterfaces();
boolean parameterized = false;
for (Type iface : interfaces) {
if (iface instanceof ParameterizedType
&& ((ParameterizedType) iface).getRawType().equals(MapFunction.class)) {
parameterized = true;
break;
}
}
if (!parameterized) {
throw new IllegalArgumentException(
"Function must implement MapFunction<IN, OUT> with type parameters");
} Prevention
- Always parameterize Flink function interfaces with concrete types
- Avoid raw type implementations of MapFunction, FlatMapFunction, etc.
- For lambdas, ensure the target functional interface has clear generics
- Do not create deep inheritance chains with raw types before the Flink interface
When it happens
Trigger: A function implements a Flink interface (e.g. MapFunction) as a raw type without type arguments, or through a chain of non-parameterized superclasses/interfaces. Also occurs with synthetic interfaces, lambda expressions, or anonymous classes where the generic signature is not available in the bytecode.
Common situations: Using a raw type like `class MyFunc implements MapFunction` without `<IN, OUT>`. Implementing a Flink interface through multiple levels of raw type inheritance. Using a lambda where the functional interface type is not resolvable through the synthetic class hierarchy.
Related errors
- The given type {} is not a parameterized type.
- Cannot convert type to class
- Tuple needs to be parameterized by using generics.
- Parameterized Tuple type expected.
- Type extraction is not possible on Either type as it does no
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a75898464e05cea4.
Report an issue: GitHub.