apache/flink · error · InvalidTypesException
Automatic type extraction is not possible on candidates with
Error message
Automatic type extraction is not possible on candidates with null values. Please specify the types directly.
What it means
Thrown by TypeExtractor.privateGetForObject when extracting type information from a Tuple instance at runtime and one of the tuple's fields is null. Flink's automatic type extraction infers types from runtime values, and a null field provides no type information, making extraction impossible.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/java/typeutils/TypeExtractor.java:2385
if (value instanceof Tuple) {
Tuple t = (Tuple) value;
int numFields = t.getArity();
if (numFields != countFieldsInClass(value.getClass())) {
// not a tuple since it has more fields.
return analyzePojo(
value.getClass(),
new ArrayList<>(),
null,
null); // we immediately call analyze Pojo here, because
// there is currently no other type that can handle such a class.
}
TypeInformation<?>[] infos = new TypeInformation[numFields];
for (int i = 0; i < numFields; i++) {
Object field = t.getField(i);
if (field == null) {
throw new InvalidTypesException(
"Automatic type extraction is not possible on candidates with null values. "
+ "Please specify the types directly.");
}
infos[i] = privateGetForObject(field);
}
return new TupleTypeInfo(value.getClass(), infos);
} else if (value instanceof Row) {
Row row = (Row) value;
int arity = row.getArity();
for (int i = 0; i < arity; i++) {
if (row.getField(i) == null) {
LOG.warn(
"Cannot extract type of Row field, because of Row field["
+ i
+ "] is null. "
+ "Should define RowTypeInfo explicitly.");
return privateGetForClass((Class<X>) value.getClass(), new ArrayList<>());View on GitHub (pinned to 2f3c205e92)
Solutions
- Provide explicit TypeInformation to avoid runtime inference: e.g., fromCollection(data, TypeInformation.of(new TypeHint<Tuple2<String,Integer>>(){})).
- Ensure sample/seed data used for type inference has no null tuple fields; use placeholder non-null values instead.
- Use .returns() with a TypeHint on the operation to bypass value-based inference.
- For nullable fields, use a POJO or Row type with explicit TypeInformation instead of Tuple.
Example fix
// before
Tuple2<String, Integer> t = new Tuple2<>("hello", null);
DataSet<Tuple2<String,Integer>> ds = env.fromElements(t);
// throws: null value prevents type extraction
// after
DataSet<Tuple2<String,Integer>> ds =
env.fromElements(new Tuple2<>("hello", 0))
.returns(TypeInformation.of(new TypeHint<Tuple2<String,Integer>>(){})); Defensive patterns
Strategy: validation
Validate before calling
// Before extracting type from a Tuple object, check for null fields
if (value instanceof Tuple) {
Tuple t = (Tuple) value;
for (int i = 0; i < t.getArity(); i++) {
if (t.getField(i) == null) {
// provide explicit TypeInformation instead of relying on runtime inference
}
}
} Type guard
static boolean tupleHasNoNulls(Object value) {
if (!(value instanceof Tuple)) return true;
Tuple t = (Tuple) value;
for (int i = 0; i < t.getArity(); i++) {
if (t.getField(i) == null) return false;
}
return true;
} Try / catch
try {
TypeInformation<?> ti = TypeExtractor.getForObject(tupleValue);
} catch (InvalidTypesException e) {
ti = TypeInformation.of(new TypeHint<Tuple2<String, Integer>>(){});
} Prevention
- Never pass Tuple instances with null fields to operations that trigger automatic type extraction.
- Use non-null placeholder values in sample/seed data.
- Provide explicit TypeInformation via fromCollection(data, typeInfo) or .returns(TypeHint).
When it happens
Trigger: Called during privateGetForObject when value is a Tuple and one of t.getField(i) returns null. This occurs when TypeExtractor.getForObject(tuple) is called on a Tuple where at least one field is null, preventing the extractor from inferring that field's TypeInformation from the runtime value.
Common situations: Creating Tuple instances with null fields and passing them to operations that trigger automatic type extraction (e.g., fromCollection, fromElements without explicit TypeInformation). Returning a Tuple with a null field from a UDF during the initial type inference pass. Testing with sample data that contains null tuple fields.
Related errors
- Wildcard expressions are not allowed here.
- Invalid format of tuple field expression "{}".
- Usage of class Tuple as a type is not allowed. Use a concret
- Tuple needs to be parameterized by using generics.
- Type information extraction for tuples (except Tuple0) canno
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/064b142c00db9d87.
Report an issue: GitHub.