apache/flink · error · NullPointerException

JobConf may not be null.

Error message

JobConf may not be null.

What it means

Thrown by the HadoopMapFunction(Mapper, JobConf) constructor when the JobConf argument is null. JobConf is required to configure the Mapper in open(); a null conf cannot be serialized or used, so construction fails fast with a NullPointerException. Note the single-arg constructor supplies a fresh JobConf() to avoid this.

Source

Thrown at flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/HadoopMapFunction.java:80

     * @param hadoopMapper The Hadoop Mapper to wrap.
     */
    public HadoopMapFunction(Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopMapper) {
        this(hadoopMapper, new JobConf());
    }

    /**
     * Maps a Hadoop Mapper (mapred API) to a Flink FlatMapFunction. The Hadoop Mapper is configured
     * with the provided JobConf.
     *
     * @param hadoopMapper The Hadoop Mapper to wrap.
     * @param conf The JobConf that is used to configure the Hadoop Mapper.
     */
    public HadoopMapFunction(Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopMapper, JobConf conf) {
        if (hadoopMapper == null) {
            throw new NullPointerException("Mapper may not be null.");
        }
        if (conf == null) {
            throw new NullPointerException("JobConf may not be null.");
        }

        this.mapper = hadoopMapper;
        this.jobConf = conf;
    }

    @PublicEvolving
    @Override
    public void open(OpenContext openContext) throws Exception {
        super.open(openContext);
        this.mapper.configure(jobConf);

        this.reporter = new HadoopDummyReporter();
        this.outputCollector = new HadoopOutputCollector<KEYOUT, VALUEOUT>();
    }

    @Override
    public void flatMap(

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Pass a non-null JobConf (or use the single-arg HadoopMapFunction(mapper) constructor, which defaults to new JobConf()).
  2. If the JobConf comes from a loader, ensure it never returns null (fail loud or supply an empty JobConf).
  3. In tests, construct a real JobConf rather than passing null.
  4. Add a null-check at the call site before constructing the wrapper.

Example fix

// before
JobConf conf = confLoader.load(); // may be null
new HadoopMapFunction(mapper, conf);
// after — ensure non-null conf, or use the default
JobConf conf = confLoader.load();
new HadoopMapFunction(mapper, conf != null ? conf : new JobConf());
Defensive patterns

Strategy: validation

Validate before calling

java.util.Objects.requireNonNull(conf, "JobConf must not be null");
new HadoopMapFunction(hadoopMapper, conf);
// or simply use the single-arg constructor that defaults to new JobConf():
new HadoopMapFunction(hadoopMapper);

Type guard

conf != null

Prevention

When it happens

Trigger: Produced when new HadoopMapFunction(hadoopMapper, conf) is called with conf == null — e.g. a JobConf reference that was never created, a configuration source returning null, or test code passing null for the conf parameter.

Common situations: A JobConf built conditionally and left null when the condition is false; a config loader returning null; copy-paste passing a null conf; tests that omit the JobConf argument. The single-arg constructor (mapper only) avoids this by defaulting to new JobConf().

Related errors


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