apache/flink · error · InvalidTypesException
Value type expected.
Error message
Value type expected.
What it means
Thrown by TypeExtractor.validateInfo when a ValueTypeInfo is expected but the extracted Java type is not a Class that extends org.apache.flink.types.Value. This means the type extractor expected a Flink Value type (custom serializable type implementing Value) but the reflected type was something else (a plain POJO, a primitive, etc.).
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:1656
}
if (component instanceof TypeVariable<?>) {
component = materializeTypeVariable(typeHierarchy, (TypeVariable<?>) component);
if (component instanceof TypeVariable) {
return;
}
}
validateInfo(
typeHierarchy,
component,
((ObjectArrayTypeInfo<?, ?>) typeInfo).getComponentInfo());
}
// check for value
else if (typeInfo instanceof ValueTypeInfo<?>) {
// check if value at all
if (!(type instanceof Class<?> && Value.class.isAssignableFrom((Class<?>) type))) {
throw new InvalidTypesException("Value type expected.");
}
TypeInformation<?> actual;
// check value type contents
if (!typeInfo.equals(
actual = ValueTypeInfo.getValueTypeInfo((Class<? extends Value>) type))) {
throw new InvalidTypesException(
"Value type '" + typeInfo + "' expected but was '" + actual + "'.");
}
}
// check for POJO
else if (typeInfo instanceof PojoTypeInfo) {
Class<?> clazz = null;
if (!(isClassType(type)
&& ((PojoTypeInfo<?>) typeInfo).getTypeClass()
== (clazz = typeToClass(type)))) {
throw new InvalidTypesException(
"POJO type '"View on GitHub (pinned to 2f3c205e92)
Solutions
- Ensure the UDF signature uses the exact Value subclass (e.g., IntValue, not int).
- Provide explicit TypeInformation via .returns(ValueTypeInfo.of(MyValue.class)) or createTypeInfo.
- If the type is genuinely not a Value type, use the correct TypeInformation (e.g., BasicTypeInfo for primitives).
- Avoid mixing Value wrappers with their primitive counterparts in generic positions.
Example fix
// before
public IntValue map(Integer v) { return new IntValue(v); } // mismatch on generic
// after
public IntValue map(Integer v) { return new IntValue(v); }
.returns(ValueTypeInfo.of(IntValue.class)) Defensive patterns
Strategy: validation
Validate before calling
// Verify the type extends Value before extraction
Class<?> clazz = typeToClass(type);
if (!Value.class.isAssignableFrom(clazz)) {
// not a Value type; use appropriate TypeInformation
ti = TypeInformation.of(clazz);
} Type guard
static boolean isValueType(Type t) {
return t instanceof Class<?> && Value.class.isAssignableFrom((Class<?>) t);
} Try / catch
try {
TypeInformation<?> ti = TypeExtractor.createTypeInfo(myFunction.getClass());
} catch (InvalidTypesException e) {
ti = ValueTypeInfo.of(MyValue.class);
} Prevention
- Ensure UDF signatures use the exact Value subclass (e.g., IntValue).
- Do not mix Flink Value wrappers with Java primitives in generic positions.
- Provide explicit .returns(ValueTypeInfo.of(...)) hints.
When it happens
Trigger: Called during validateInfo when TypeInformation is a ValueTypeInfo but the reflected type is not a Class assignable to Value.class. This occurs when a UDF declares its type as a Value subclass (e.g., IntValue, StringValue, or a custom Value) but the actual generic type argument resolves to a different class, a TypeVariable, or a raw type.
Common situations: Declaring a function with a Value type but using a different type in the actual implementation. Mixing Flink Value wrapper types (IntValue, StringValue) with their Java primitive equivalents (int, String). Custom Value subclasses used incorrectly in generic hierarchies where erasure hides the actual type.
Related errors
- Object array type expected.
- Enum type expected.
- POJO type '{}' expected but was '{}'.
- Enum type '{}' expected but was '{}'.
- Generic type '{}' or a subclass of it expected but was '{}'.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/17c4d38b7139310b.
Report an issue: GitHub.