{"record":{"id":"b4c3126e0f10c066","repo":"apache/flink","slug":"type-of-typevariable-in-could-not-be-det","errorCode":null,"errorMessage":"Type of TypeVariable '{}' in '{}' could not be determined. This is most likely a type erasure problem. The type extraction currently supports types with generic variables only in cases where all variables in the return type can be deduced from the input type(s). Otherwise the type has to be specified explicitly using type information.","messagePattern":"Type of TypeVariable '(.+?)' in '(.+?)' could not be determined\\. This is most likely a type erasure problem\\. The type extraction currently supports types with generic variables only in cases where all variables in the return type can be deduced from the input type\\(s\\)\\. 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/TypeExtractor.java","lineNumber":965,"sourceCode":"        // type depends on another type\n        // e.g. class MyMapper<E> extends MapFunction<String, E>\n        else if (t instanceof TypeVariable) {\n            Type typeVar = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) t);\n\n            if (!(typeVar instanceof TypeVariable)) {\n                return createTypeInfoWithTypeHierarchy(typeHierarchy, typeVar, in1Type, in2Type);\n            }\n            // try to derive the type info of the TypeVariable from the immediate base child input\n            // as a last attempt\n            else {\n                TypeInformation<OUT> typeInfo =\n                        (TypeInformation<OUT>)\n                                createTypeInfoFromInputs(\n                                        (TypeVariable<?>) t, typeHierarchy, in1Type, in2Type);\n                if (typeInfo != null) {\n                    return typeInfo;\n                } else {\n                    throw new InvalidTypesException(\n                            \"Type of TypeVariable '\"\n                                    + ((TypeVariable<?>) t).getName()\n                                    + \"' in '\"\n                                    + ((TypeVariable<?>) t).getGenericDeclaration()\n                                    + \"' could not be determined. This is most likely a type erasure problem. \"\n                                    + \"The type extraction currently supports types with generic variables only in cases where \"\n                                    + \"all variables in the return type can be deduced from the input type(s). \"\n                                    + \"Otherwise the type has to be specified explicitly using type information.\");\n                }\n            }\n        }\n        // arrays with generics\n        else if (t instanceof GenericArrayType) {\n            GenericArrayType genericArray = (GenericArrayType) t;\n\n            Type componentType = genericArray.getGenericComponentType();\n\n            // due to a Java 6 bug, it is possible that the JVM classifies e.g. String[] or int[] as","sourceCodeStart":947,"sourceCodeEnd":983,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L947-L983","documentation":"Thrown when a function's return type is a TypeVariable (e.g. `<E>` in `class MyMapper<E> extends MapFunction<String, E>`) that could not be resolved through the type hierarchy and could not be deduced from the input type information. Java type erasure strips generic type arguments at runtime, so Flink must trace the variable through the class hierarchy and input types — if that trace fails, extraction is impossible without explicit hints.","triggerScenarios":"A generic function class like `class MyMapper<E> extends MapFunction<String, E>` is used without specifying E at the call site, and the input type does not carry enough information to infer E. This is the terminal failure after `materializeTypeVariable` returns an unresolved TypeVariable and `createTypeInfoFromInputs` returns null.","commonSituations":"Writing a reusable generic MapFunction or FlatMapFunction with an unresolved type parameter. Using lambda expressions where the return type variable cannot be traced. Subclassing a Flink function interface with an intermediate abstract generic class that does not bind the variable.","solutions":["Provide the TypeInformation explicitly via `.returns(TypeInformation.of(MyOutputType.class))` on the DataStream","Make the function class non-generic by binding the type variable: `class StringToLongMapper extends MapFunction<String, Long>` instead of `<E> extends MapFunction<String, E>`","Implement ResultTypeQueryable and return the concrete TypeInformation from getProducedType()","Use a TypeHint: `TypeInformation.of(new TypeHint<MyType>(){})`"],"exampleFix":"// before\npublic class JsonExtractor<T> extends MapFunction<String, T> { ... }\n\n// after — bind the type or use .returns()\ndataStream.map(new JsonExtractor<MyEvent>())\n          .returns(TypeInformation.of(MyEvent.class));","handlingStrategy":"validation","validationCode":"// Verify the function's return type is fully resolved before use\ntry {\n    TypeInformation<?> returnInfo = TypeExtractor.createTypeInfo(\n        myFunction, MapFunction.class, myFunction.getClass(), 1);\n} catch (InvalidTypesException e) {\n    // Provide explicit type info\n    dataStream.map(myFunction).returns(TypeInformation.of(MyOutputType.class));\n}","typeGuard":null,"tryCatchPattern":"// Catch and provide explicit type information\ntry {\n    resultStream = inputStream.map(myGenericFunction);\n} catch (InvalidTypesException e) {\n    resultStream = inputStream.map(myGenericFunction)\n        .returns(TypeInformation.of(MyType.class));\n}","preventionTips":["Avoid defining generic type variables on function classes unless you also implement ResultTypeQueryable","Always use `.returns(TypeInformation.of(...))` when the output type involves generics","Test type extraction with TypeExtractor.createTypeInfo() in unit tests","Prefer concrete type parameters in function class definitions"],"tags":["type-extraction","type-erasure","generics","type-variable"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}