apache/flink · error · IllegalArgumentException
Type for included field {} should not be null.
Error message
Type for included field {} should not be null. What it means
Thrown by GenericCsvInputFormat.setFieldsGeneric(boolean[], Class<?>[]) when an included field (mask[i]==true) is paired with a null type entry. While null entries are allowed in the simple setFieldTypesGeneric overload (meaning 'skip'), in the mask variant every included position must have a concrete type because the parser must be constructed for it.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java:283
protected void setFieldsGeneric(boolean[] includedMask, Class<?>[] fieldTypes) {
checkNotNull(includedMask);
checkNotNull(fieldTypes);
ArrayList<Class<?>> types = new ArrayList<Class<?>>();
// check if types are valid for included fields
int typeIndex = 0;
for (int i = 0; i < includedMask.length; i++) {
if (includedMask[i]) {
if (typeIndex > fieldTypes.length - 1) {
throw new IllegalArgumentException(
"Missing type for included field " + i + ".");
}
Class<?> type = fieldTypes[typeIndex++];
if (type == null) {
throw new IllegalArgumentException(
"Type for included field " + i + " should not be null.");
} else {
// check if we support parsers for this type
if (FieldParser.getParserForType(type) == null) {
throw new IllegalArgumentException(
"The type '"
+ type.getName()
+ "' is not supported for the CSV input format.");
}
types.add(type);
}
}
}
this.fieldTypes = types.toArray(new Class<?>[types.size()]);
this.fieldIncluded = includedMask;
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Provide a concrete supported type for every included (mask true) position.
- If a column should be skipped, set its mask entry to false rather than supplying a null type.
- Validate with: if (mask[i]) Objects.requireNonNull(types[typeIndex]).
Example fix
// before
boolean[] mask = {true, true};
Class<?>[] types = {Integer.class, null}; // null for included field
format.setFieldsGeneric(mask, types);
// after
boolean[] mask = {true, false}; // skip second column instead
Class<?>[] types = {Integer.class};
format.setFieldsGeneric(mask, types); Defensive patterns
Strategy: validation
Validate before calling
int ti = 0;
for (int i = 0; i < includedMask.length; i++) {
if (includedMask[i]) {
Objects.requireNonNull(fieldTypes[ti], "type for included field " + i + " must not be null");
ti++;
}
}
format.setFieldsGeneric(includedMask, fieldTypes); Type guard
static boolean noNullTypeForIncluded(boolean[] mask, Class<?>[] types) {
int ti = 0;
for (boolean b : mask) {
if (b) {
if (types[ti] == null) return false;
ti++;
}
}
return true;
} Prevention
- Set mask[i] = false to skip a column rather than supplying a null type.
- Provide a concrete type for every included position.
- Validate types against the mask before calling the API.
When it happens
Trigger: Building the fieldTypes array with a null slot that aligns with a true position in the mask; reusing a partially-null types array from another context.
Common situations: Refactoring that nulls out a type but leaves the mask position selected; mixing the 'skip via null' convention from the other overload into this mask-based API.
Related errors
- Field types must not be null.
- Delimiter must not be null
- Missing type for included field {}.
- The type '{}' is not supported for the CSV input format.
- Field indices must not be smaller than zero.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a134f59699f3747d.
Report an issue: GitHub.