apache/flink · error · NullPointerException

Hadoop input split must not be null

Error message

Hadoop input split must not be null

What it means

Thrown by the HadoopInputSplit constructor when the hadoop InputSplit argument is null. A null InputSplit has no split data to read from, so the constructor rejects it immediately rather than failing later during reads. This is a programmer error in code that constructs HadoopInputSplit objects.

Source

Thrown at flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/api/java/hadoop/mapred/wrapper/HadoopInputSplit.java:58

@Internal
public class HadoopInputSplit extends LocatableInputSplit {

    private static final long serialVersionUID = -6990336376163226160L;

    private final Class<? extends org.apache.hadoop.mapred.InputSplit> splitType;

    private transient org.apache.hadoop.mapred.InputSplit hadoopInputSplit;

    @Nullable private transient JobConf jobConf;

    public HadoopInputSplit(
            int splitNumber,
            org.apache.hadoop.mapred.InputSplit hInputSplit,
            @Nullable JobConf jobconf) {
        super(splitNumber, (String) null);

        if (hInputSplit == null) {
            throw new NullPointerException("Hadoop input split must not be null");
        }

        if (needsJobConf(hInputSplit) && jobconf == null) {
            throw new NullPointerException(
                    "Hadoop JobConf must not be null when input split is configurable.");
        }

        this.splitType = hInputSplit.getClass();

        this.jobConf = jobconf;
        this.hadoopInputSplit = hInputSplit;
    }

    // ------------------------------------------------------------------------
    //  Properties
    // ------------------------------------------------------------------------

    @Override

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Ensure the Hadoop InputSplit passed to HadoopInputSplit is non-null — check the return of getSplits() before wrapping.
  2. If getSplits() can legitimately return no splits, handle the empty case before constructing HadoopInputSplit objects.
  3. Add a null check in the calling code before constructing the split wrapper.

Example fix

// before
org.apache.hadoop.mapred.InputSplit hadoopSplit = format.getSplits(jobConf, 0).get(0);
HadoopInputSplit split = new HadoopInputSplit(0, hadoopSplit, jobConf);
// after
InputSplit[] splits = format.getSplits(jobConf, numSplits);
if (splits == null || splits.length == 0) {
    throw new IllegalStateException("Hadoop InputFormat returned no splits");
}
HadoopInputSplit split = new HadoopInputSplit(0, splits[0], jobConf);
Defensive patterns

Strategy: validation

Validate before calling

// Validate InputSplit is non-null before constructing HadoopInputSplit
Objects.requireNonNull(hInputSplit, "Hadoop InputSplit must not be null");
if (hInputSplit == null) {
    throw new NullPointerException("Hadoop InputSplit from getSplits() is null");
}
HadoopInputSplit split = new HadoopInputSplit(splitNumber, hInputSplit, jobConf);

Prevention

When it happens

Trigger: Constructing a new HadoopInputSplit(splitNumber, null, jobConf) — typically in custom input format wrappers or test code that fails to obtain a real InputSplit from Hadoop's getSplits().

Common situations: Hadoop InputFormat.getSplits() returning null instead of an empty list; custom wrapper code that passes through a null split; test fixtures that forget to populate the split.

Related errors


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