{"record":{"id":"b34e032883eee128","repo":"apache/flink","slug":"type-extraction-is-not-possible-on-either-type-as","errorCode":null,"errorMessage":"Type extraction is not possible on Either type as it does not contain information about the 'left' type.","messagePattern":"Type extraction is not possible on Either type as it does not contain information about the 'left' type\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/EitherTypeInfoFactory.java","lineNumber":38,"sourceCode":"\nimport org.apache.flink.api.common.functions.InvalidTypesException;\nimport org.apache.flink.api.common.typeinfo.TypeInfoFactory;\nimport org.apache.flink.api.common.typeinfo.TypeInformation;\nimport org.apache.flink.types.Either;\n\nimport java.lang.reflect.Type;\nimport java.util.Map;\n\npublic class EitherTypeInfoFactory<L, R> extends TypeInfoFactory<Either<L, R>> {\n\n    @Override\n    public TypeInformation<Either<L, R>> createTypeInfo(\n            Type t, Map<String, TypeInformation<?>> genericParameters) {\n        TypeInformation<?> leftType = genericParameters.get(\"L\");\n        TypeInformation<?> rightType = genericParameters.get(\"R\");\n\n        if (leftType == null) {\n            throw new InvalidTypesException(\n                    \"Type extraction is not possible on Either\"\n                            + \" type as it does not contain information about the 'left' type.\");\n        }\n\n        if (rightType == null) {\n            throw new InvalidTypesException(\n                    \"Type extraction is not possible on Either\"\n                            + \" type as it does not contain information about the 'right' type.\");\n        }\n\n        return new EitherTypeInfo(leftType, rightType);\n    }\n}\n","sourceCodeStart":20,"sourceCodeEnd":52,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/EitherTypeInfoFactory.java#L20-L52","documentation":"Thrown by EitherTypeInfoFactory.createTypeInfo() when the generic parameter 'L' (the Left type of Either<L,R>) was not resolved during type extraction. Either carries two type parameters; if Flink cannot infer the left one (because the type information was erased or never supplied), the factory refuses to produce a bogus EitherTypeInfo.","triggerScenarios":"Using Either<L,R> as a function return type or in a TypeInformation hint without enough generic information for the extractor to bind L; annotating with @TypeInfo and letting EitherTypeInfoFactory run with a missing 'L' entry in genericParameters.","commonSituations":"Returning Either from a lambda whose generic type is erased; using raw Either; subclassing Either without preserving type arguments; a MapFunction<Either<X,Y>, ...> where X cannot be inferred.","solutions":["Provide an explicit TypeInformation or Returns hint: .returns(TypeInformation.of(new TypeHint<Either<LeftT,RightT>>(){})).","Avoid raw Either; always parameterize it and ensure both type arguments are concrete and inferable.","Wrap the function in a named class with explicit generic signature so the extractor can read L."],"exampleFix":"// before\nDataStream<Either> out = in.map(x -> Either.Left(x)); // raw Either, L unknown\n\n// after\nDataStream<Either<String,Integer>> out = in\n  .map(x -> Either.Left(x.toString()))\n  .returns(TypeInformation.of(new TypeHint<Either<String,Integer>>(){}));","handlingStrategy":"validation","validationCode":"// Ensure 'L' is inferable by providing an explicit TypeHint\nTypeInformation<Either<LeftT, RightT>> ti =\n    TypeInformation.of(new TypeHint<Either<LeftT, RightT>>(){});","typeGuard":"// Type guard: both type args present\nstatic <L,R> TypeInformation<Either<L,R>> eitherTi(Class<L> l, Class<R> r) {\n    return new EitherTypeInfo<>(TypeInformation.of(l), TypeInformation.of(r));\n}","tryCatchPattern":null,"preventionTips":["Always parameterize Either with both type arguments.","Provide a .returns() TypeHint when using Either in lambdas.","Avoid raw Either in signatures."],"tags":["type-extraction","either","generics","type-info"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}