apache/flink · error · InvalidTypesException
Basic type expected.
Error message
Basic type expected.
What it means
Thrown during input type validation when the TypeInformation is a BasicTypeInfo (wrapping a Java primitive wrapper like Integer, String, Double, etc.) but the reflected Type is not a recognized basic type. `BasicTypeInfo.getInfoFor()` returns null for the class, meaning it is not one of the supported basic types (String, Boolean, Byte, Short, Integer, Long, Float, Double, Character, Void, BigDecimal, BigInteger, Date, etc.).
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:1505
private static void validateInfo(
List<Type> typeHierarchy, Type type, TypeInformation<?> typeInfo) {
if (type == null) {
throw new InvalidTypesException("Unknown Error. Type is null.");
}
if (typeInfo == null) {
throw new InvalidTypesException("Unknown Error. TypeInformation is null.");
}
if (!(type instanceof TypeVariable<?>)) {
// check for Java Basic Types
if (typeInfo instanceof BasicTypeInfo) {
TypeInformation<?> actual;
// check if basic type at all
if (!(type instanceof Class<?>)
|| (actual = BasicTypeInfo.getInfoFor((Class<?>) type)) == null) {
throw new InvalidTypesException("Basic type expected.");
}
// check if correct basic type
if (!typeInfo.equals(actual)) {
throw new InvalidTypesException(
"Basic type '" + typeInfo + "' expected but was '" + actual + "'.");
}
}
// check for Java SQL time types
else if (typeInfo instanceof SqlTimeTypeInfo) {
TypeInformation<?> actual;
// check if SQL time type at all
if (!(type instanceof Class<?>)
|| (actual = SqlTimeTypeInfo.getInfoFor((Class<?>) type)) == null) {
throw new InvalidTypesException("SQL time type expected.");
}
// check if correct SQL time typeView on GitHub (pinned to 2f3c205e92)
Solutions
- Ensure the function's input type parameter is a recognized Java basic type (String, Integer, Long, Double, etc.)
- Transform the stream with a prior map to convert to the correct basic type
- Fix the function signature to use the correct input type matching the stream
Example fix
// before — function expects basic type, stream carries POJO
DataStream<MyEvent> events = ...;
events.map(new MapFunction<Integer, String>() { ... });
// after — align types
events.map(event -> event.getCount()) // extract basic type first
.map(new MapFunction<Integer, String>() { ... }); Defensive patterns
Strategy: validation
Validate before calling
// Verify the stream's element type is a recognized Flink basic type
TypeInformation<?> elementType = stream.getType();
if (elementType instanceof BasicTypeInfo) {
// OK — stream carries a basic type
} else {
throw new IllegalStateException(
"Expected a basic type stream but got: " + elementType);
} Prevention
- Ensure the function's input type parameter is a recognized Java basic type
- Check Types.BASIC_TYPES or BasicTypeInfo for the list of supported basic types
- Add explicit type conversion maps when connecting streams of different element types
- Use TypeInformation.of(ExpectedType.class) to verify expected types before connecting
When it happens
Trigger: A function declares BasicTypeInfo as its input type information but the actual reflected type from the function signature is a non-basic class. For example, the DataStream expects a basic type but the function signature specifies a custom POJO or enum.
Common situations: Connecting a function that expects `MapFunction<Integer, X>` to a stream of custom POJOs. Using a non-standard type where a basic Java type is expected. Mismatches between the TypeInformation registered on the DataStream and the function's declared input type.
Related errors
- Basic type '{}' expected but was '{}'.
- SQL time type expected.
- SQL time type '{}' expected but was '{}'.
- Tuple type expected.
- Concrete subclass of Tuple expected.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a6a2a63b39d52951.
Report an issue: GitHub.