{"record":{"id":"b877e1c18954aa83","repo":"apache/flink","slug":"the-generic-type-parameters-of-are-missing-i","errorCode":null,"errorMessage":"The generic type parameters of '{}' are missing. In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved. An easy workaround is to use an (anonymous) class instead that implements the '{}' interface. Otherwise the type has to be specified explicitly using type information.","messagePattern":"The generic type parameters of '(.+?)' are missing\\. In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved\\. An easy workaround is to use an \\(anonymous\\) class instead that implements the '(.+?)' interface\\. Otherwise the type has to be specified explicitly using type information\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java","lineNumber":366,"sourceCode":"            Type component = ((GenericArrayType) t).getGenericComponentType();\n            return Array.newInstance(getRawClass(component), 0).getClass();\n        }\n        return Object.class;\n    }\n\n    /**\n     * Checks whether the given type has the generic parameters declared in the class definition.\n     *\n     * @param t type to be validated\n     */\n    public static void validateLambdaType(Class<?> baseClass, Type t) {\n        if (!(t instanceof Class)) {\n            return;\n        }\n        final Class<?> clazz = (Class<?>) t;\n\n        if (clazz.getTypeParameters().length > 0) {\n            throw new InvalidTypesException(\n                    \"The generic type parameters of '\"\n                            + clazz.getSimpleName()\n                            + \"' are missing. \"\n                            + \"In many cases lambda methods don't provide enough information for automatic type extraction when Java generics are involved. \"\n                            + \"An easy workaround is to use an (anonymous) class instead that implements the '\"\n                            + baseClass.getName()\n                            + \"' interface. \"\n                            + \"Otherwise the type has to be specified explicitly using type information.\");\n        }\n    }\n\n    /**\n     * Will return true if the type of the given generic class type matches clazz.\n     *\n     * @param clazz The generic class to check against\n     * @param type The type to be checked\n     */\n    public static boolean isGenericOfClass(Class<?> clazz, Type type) {","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractionUtils.java#L348-L384","documentation":"Thrown by TypeExtractionUtils.validateLambdaType when a lambda's output type is a raw Class that has declared type parameters (getTypeParameters().length > 0) but no actual type arguments were provided. This is the classic 'type erasure in lambda' problem: the JVM erases generic information from lambda implementations, so the extractor sees a raw class (e.g. Tuple2 instead of Tuple2<String, Integer>) and cannot determine the field types.","triggerScenarios":"A lambda returns a generic type without explicit type information: ds.map(x -> new Tuple2(x, x.length())) where Tuple2's generic parameters are erased. Using a method reference to a method that returns a generic type without type witness. Lambda returning a List, Map, or other generic collection without type arguments.","commonSituations":"Most common type-extraction failure for Flink users. Happens when using lambdas with generics like Tuple2, Tuple3, POJOs with generic fields, or collections. The Java compiler cannot always preserve enough generic metadata through lambda deserialization for Flink's reflect-based extractor.","solutions":["Specify the return type explicitly: ds.map(...).returns(TypeInformation.of(new TypeHint<Tuple2<String,Integer>>(){})).","Replace the lambda with an anonymous inner class that has explicit generic type arguments.","Implement ResultTypeQueryable on a named class and return the TypeInformation from getProducedType().","Use .returns(Types.TUPLE(Types.STRING, Types.INT)) for concise type specification."],"exampleFix":"// before\nds.map(x -> new Tuple2<>(x, x.length()))\n// after\nds.map(x -> new Tuple2<>(x, x.length()))\n  .returns(Types.TUPLE(Types.STRING, Types.INT));","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    ds.map(x -> new Tuple2<>(x, x.length()));\n} catch (InvalidTypesException e) {\n    // lambda erased generics; specify type explicitly\n    ds.map(x -> new Tuple2<>(x, x.length()))\n      .returns(Types.TUPLE(Types.STRING, Types.INT));\n}","preventionTips":["Always chain .returns(TypeInformation.of(new TypeHint<...>(){})) after lambda map/flatMap that returns generics.","Prefer anonymous classes with explicit type arguments for complex generic return types.","Use Types.* helper for concise type specification (e.g. Types.TUPLE(Types.STRING, Types.INT)).","Implement ResultTypeQueryable for reusable function classes."],"tags":["type-extraction","lambda","generics","type-erasure","common"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}