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
- Pass a non-null JobConf (or use the single-arg HadoopMapFunction(mapper) constructor, which defaults to new JobConf()).
- If the JobConf comes from a loader, ensure it never returns null (fail loud or supply an empty JobConf).
- In tests, construct a real JobConf rather than passing null.
- 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
- Pass a non-null JobConf, or use the HadoopMapFunction(mapper) constructor.
- Ensure config loaders never return null (default to new JobConf()).
- In tests, construct a real JobConf.
- Guard the conf reference with Objects.requireNonNull before constructing.
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
- Mapper may not be null.
- Hadoop input split must not be null
- The collection contains a null element
- The collection contains a null element
- Unable to instantiate Hadoop InputSplit
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/821c7ebd097b77d1.
Report an issue: GitHub.