{"record":{"id":"a75898464e05cea4","repo":"apache/flink","slug":"the-types-of-the-interface-could-not-be-inferre","errorCode":null,"errorMessage":"The types of the interface {} could not be inferred. Support for synthetic interfaces, lambdas, and generic or raw types is limited at this point","messagePattern":"The types of the interface (.+?) could not be inferred\\. Support for synthetic interfaces, lambdas, and generic or raw types is limited at this point","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":1428,"sourceCode":"        }\n        Type[] interfaceTypes = clazz.getGenericInterfaces();\n\n        // search in interfaces for base class\n        for (Type t : interfaceTypes) {\n            Type parameter = getParameterTypeFromGenericType(baseClass, typeHierarchy, t, pos);\n            if (parameter != null) {\n                return parameter;\n            }\n        }\n\n        // search in superclass for base class\n        Type t = clazz.getGenericSuperclass();\n        Type parameter = getParameterTypeFromGenericType(baseClass, typeHierarchy, t, pos);\n        if (parameter != null) {\n            return parameter;\n        }\n\n        throw new InvalidTypesException(\n                \"The types of the interface \"\n                        + baseClass.getName()\n                        + \" could not be inferred. \"\n                        + \"Support for synthetic interfaces, lambdas, and generic or raw types is limited at this point\");\n    }\n\n    private static Type getParameterTypeFromGenericType(\n            Class<?> baseClass, List<Type> typeHierarchy, Type t, int pos) {\n        // base class\n        if (t instanceof ParameterizedType\n                && baseClass.equals(((ParameterizedType) t).getRawType())) {\n            if (typeHierarchy != null) {\n                typeHierarchy.add(t);\n            }\n            ParameterizedType baseClassChild = (ParameterizedType) t;\n            return baseClassChild.getActualTypeArguments()[pos];\n        }\n        // interface that extended base class as class or parameterized type","sourceCodeStart":1410,"sourceCodeEnd":1446,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L1410-L1446","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before — raw interface implementation\nclass MyFunc implements MapFunction {\n    public Object map(Object value) { ... }\n}\n\n// after — parameterized\nclass MyFunc implements MapFunction<String, MyEvent> {\n    public MyEvent map(String value) { ... }\n}","handlingStrategy":"validation","validationCode":"// Check that the function class parameterizes the Flink interface\nType[] interfaces = myFunction.getClass().getGenericInterfaces();\nboolean parameterized = false;\nfor (Type iface : interfaces) {\n    if (iface instanceof ParameterizedType\n            && ((ParameterizedType) iface).getRawType().equals(MapFunction.class)) {\n        parameterized = true;\n        break;\n    }\n}\nif (!parameterized) {\n    throw new IllegalArgumentException(\n        \"Function must implement MapFunction<IN, OUT> with type parameters\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["type-extraction","interface","raw-type","generics","reflection"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}