apache/flink · error · IllegalArgumentException

Field types must not be null.

Error message

Field types must not be null.

What it means

Thrown by GenericCsvInputFormat.setFieldTypesGeneric(Class<?>... fieldTypes) when the fieldTypes array itself is null. The method allocates the fieldIncluded mask of length fieldTypes.length, so a null array cannot proceed. Note: individual null entries inside the array are allowed and mean 'skip this position'.

Source

Thrown at flink-core/src/main/java/org/apache/flink/api/common/io/GenericCsvInputFormat.java:204

            return this.fieldTypes;
        } else {
            // sparse type array which we made dense for internal book keeping.
            // create a sparse copy to return
            Class<?>[] types = new Class<?>[this.fieldIncluded.length];

            for (int i = 0, k = 0; i < this.fieldIncluded.length; i++) {
                if (this.fieldIncluded[i]) {
                    types[i] = this.fieldTypes[k++];
                }
            }

            return types;
        }
    }

    protected void setFieldTypesGeneric(Class<?>... fieldTypes) {
        if (fieldTypes == null) {
            throw new IllegalArgumentException("Field types must not be null.");
        }

        this.fieldIncluded = new boolean[fieldTypes.length];
        ArrayList<Class<?>> types = new ArrayList<Class<?>>();

        // check if we support parsers for these types
        for (int i = 0; i < fieldTypes.length; i++) {
            Class<?> type = fieldTypes[i];

            if (type != null) {
                if (FieldParser.getParserForType(type) == null) {
                    throw new IllegalArgumentException(
                            "The type '"
                                    + type.getName()
                                    + "' is not supported for the CSV input format.");
                }
                types.add(type);
                fieldIncluded[i] = true;

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Pass a non-null Class<?>[] (even an empty array if zero columns are selected).
  2. Guard the builder: types = types != null ? types : new Class<?>[0] before calling.
  3. Ensure your subclass constructs the types array from a validated schema.

Example fix

// before
format.setFieldTypesGeneric(types); // types is null

// after
Class<?>[] types = schema != null ? schema.getTypes() : new Class<?>[0];
format.setFieldTypesGeneric(types);
Defensive patterns

Strategy: validation

Validate before calling

Class<?>[] types = schema != null ? schema.getTypes() : new Class<?>[0];
Objects.requireNonNull(types, "field types array must not be null");
format.setFieldTypesGeneric(types);

Prevention

When it happens

Trigger: Calling setFieldTypesGeneric((Class<?>[]) null); a subclass passing a null types array from a config-driven builder; varargs misuse that resolves to a null array.

Common situations: Dynamic CSV schema where the type array was not built because no columns were configured; refactoring that leaves the types array uninitialized.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/3dd00f9c7865375c. Report an issue: GitHub.