{"record":{"id":"64d852725a1c12bc","repo":"apache/flink","slug":"basic-type-expected-but-was","errorCode":null,"errorMessage":"Basic type '{}' expected but was '{}'.","messagePattern":"Basic type '(.+?)' expected but was '(.+?)'\\.","errorType":"exception","errorClass":"InvalidTypesException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java","lineNumber":1509,"sourceCode":"        }\n\n        if (typeInfo == null) {\n            throw new InvalidTypesException(\"Unknown Error. TypeInformation is null.\");\n        }\n\n        if (!(type instanceof TypeVariable<?>)) {\n            // check for Java Basic Types\n            if (typeInfo instanceof BasicTypeInfo) {\n\n                TypeInformation<?> actual;\n                // check if basic type at all\n                if (!(type instanceof Class<?>)\n                        || (actual = BasicTypeInfo.getInfoFor((Class<?>) type)) == null) {\n                    throw new InvalidTypesException(\"Basic type expected.\");\n                }\n                // check if correct basic type\n                if (!typeInfo.equals(actual)) {\n                    throw new InvalidTypesException(\n                            \"Basic type '\" + typeInfo + \"' expected but was '\" + actual + \"'.\");\n                }\n\n            }\n            // check for Java SQL time types\n            else if (typeInfo instanceof SqlTimeTypeInfo) {\n\n                TypeInformation<?> actual;\n                // check if SQL time type at all\n                if (!(type instanceof Class<?>)\n                        || (actual = SqlTimeTypeInfo.getInfoFor((Class<?>) type)) == null) {\n                    throw new InvalidTypesException(\"SQL time type expected.\");\n                }\n                // check if correct SQL time type\n                if (!typeInfo.equals(actual)) {\n                    throw new InvalidTypesException(\n                            \"SQL time type '\" + typeInfo + \"' expected but was '\" + actual + \"'.\");\n                }","sourceCodeStart":1491,"sourceCodeEnd":1527,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java#L1491-L1527","documentation":"Thrown during input type validation when both the expected and actual types are BasicTypeInfo, but they do not match. The function declares one basic type (e.g. Integer) in its signature but the DataStream's TypeInformation represents a different basic type (e.g. String). This is a type-safety check to catch incompatible basic type assignments before runtime serialization errors.","triggerScenarios":"A function signature says `MapFunction<String, X>` but the DataStream carries `DataStream<Integer>`. Both are basic types, but they are different basic types. The `typeInfo.equals(actual)` check fails, producing this error with both type names.","commonSituations":"Refactoring a pipeline to change element types without updating function signatures. Mixing up column orders or field types in a transformation chain. Connecting operators designed for different basic types.","solutions":["Align the function's input type parameter with the DataStream's element type","Add a conversion map to transform the stream element type before the function","Fix the function signature to declare the correct input basic type"],"exampleFix":"// before — type mismatch\nDataStream<Integer> counts = ...;\ncounts.map(new MapFunction<String, String>() { ... }); // expects String, got Integer\n\n// after — align types\ncounts.map(new MapFunction<Integer, String>() {\n    public String map(Integer value) { return value.toString(); }\n});","handlingStrategy":"validation","validationCode":"// Pre-check that basic types match\nTypeInformation<?> streamType = stream.getType();\nTypeInformation<?> funcInputType = TypeInformation.of(Integer.class);\nif (streamType instanceof BasicTypeInfo\n        && funcInputType instanceof BasicTypeInfo\n        && !streamType.equals(funcInputType)) {\n    throw new IllegalStateException(\n        \"Type mismatch: stream has \" + streamType + \" but function expects \" + funcInputType);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always verify that the DataStream's element type matches the function's declared input type","Use type-safe builders or wrappers that check at compile time when possible","Add a conversion map between incompatible basic types before the function","Run integration tests that exercise the full pipeline to catch type mismatches early"],"tags":["type-validation","basic-type","type-mismatch","reflection"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}