apache/flink · error · IllegalArgumentException
Input format may not be null.
Error message
Input format may not be null.
What it means
Thrown by the GenericDataSourceBase(T format, OperatorInformation, String name) constructor when the supplied InputFormat instance is null. The source operator wraps user code, and a null format would cause an NPE later during plan traversal or execution, so it is rejected at construction time.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/operators/GenericDataSourceBase.java:66
protected final UserCodeWrapper<? extends T> formatWrapper;
protected String statisticsKey;
private SplitDataProperties splitProperties;
/**
* Creates a new instance for the given file using the given input format.
*
* @param format The {@link org.apache.flink.api.common.io.InputFormat} implementation used to
* read the data.
* @param operatorInfo The type information for the operator.
* @param name The given name for the Pact, used in plans, logs and progress messages.
*/
public GenericDataSourceBase(T format, OperatorInformation<OUT> operatorInfo, String name) {
super(operatorInfo, name);
if (format == null) {
throw new IllegalArgumentException("Input format may not be null.");
}
this.formatWrapper = new UserCodeObjectWrapper<T>(format);
}
/**
* Creates a new instance for the given file using the given input format, using the default
* name.
*
* @param format The {@link org.apache.flink.api.common.io.InputFormat} implementation used to
* read the data.
* @param operatorInfo The type information for the operator.
*/
public GenericDataSourceBase(T format, OperatorInformation<OUT> operatorInfo) {
super(operatorInfo, DEFAULT_NAME);
if (format == null) {
throw new IllegalArgumentException("Input format may not be null.");View on GitHub (pinned to 2f3c205e92)
Solutions
- Ensure the InputFormat instance is created before constructing the source; never pass a value that may be null.
- If the format is optional, return early / throw a clearer domain exception at the call site instead of relying on this guard.
- Audit factory methods that produce the format argument for unchecked null returns.
Example fix
// before
InputFormat<OUT,?> fmt = registry.get(name);
new GenericDataSourceBase<>(fmt, opInfo, "src");
// after
InputFormat<OUT,?> fmt = registry.get(name);
if (fmt == null) throw new IllegalStateException("No format registered for " + name);
new GenericDataSourceBase<>(fmt, opInfo, "src"); Defensive patterns
Strategy: validation
Validate before calling
if (format == null) throw new IllegalStateException("InputFormat not built for " + name);
new GenericDataSourceBase<>(format, opInfo, name); Prevention
- Never forward a possibly-null format into a constructor; guard at the call site.
- Use Objects.requireNonNull(format, "input format") for a clear failure point.
- Audit factory/supplier methods that produce formats for unchecked null returns.
When it happens
Trigger: Constructing a GenericDataSourceBase directly (rare in user code; usually internal/API-layer code) and passing a null InputFormat object, e.g. when a factory method returned null and the result was forwarded unchecked.
Common situations: Framework/library code building operators programmatically; a refactor where the format argument comes from a Map.get() that returns null; tests that stub the format supplier without a default.
Related errors
- Unable to instantiate the hadoop input format
- Unable to find key class.
- Unable to find value class.
- Could not get KeyValue pair.
- Could not get Splits.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/fe4c0cb32ec2bf81.
Report an issue: GitHub.