apache/flink · error · NullPointerException
JobConf may not be null.
Error message
JobConf may not be null.
What it means
Thrown by the HadoopReducerWrappedFunction two-arg constructor when the JobConf argument is null. The JobConf is stored and later passed to reducer.configure(jobConf) in open(); a null conf would NPE inside the Hadoop Reducer lifecycle. The one-arg constructor avoids this by supplying a default new JobConf(), so this only fires when you explicitly pass null to the two-arg overload.
Source
Thrown at flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/HadoopReducerWrappedFunction.java:93
* @param hadoopReducer The Hadoop Reducer to wrap.
*/
public HadoopReducerWrappedFunction(Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopReducer) {
this(hadoopReducer, new JobConf());
}
/**
* Maps a Hadoop Reducer (mapred API) to a non-combinable Flink GroupReduceFunction.
*
* @param hadoopReducer The Hadoop Reducer to wrap.
* @param conf The JobConf that is used to configure the Hadoop Reducer.
*/
public HadoopReducerWrappedFunction(
Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopReducer, JobConf conf) {
if (hadoopReducer == null) {
throw new NullPointerException("Reducer may not be null.");
}
if (conf == null) {
throw new NullPointerException("JobConf may not be null.");
}
this.reducer = hadoopReducer;
this.jobConf = conf;
}
@SuppressWarnings("unchecked")
@PublicEvolving
@Override
public void open(OpenContext openContext) throws Exception {
super.open(openContext);
this.reducer.configure(jobConf);
this.reporter = new HadoopDummyReporter();
this.reduceCollector = new HadoopOutputCollector<KEYOUT, VALUEOUT>();
Class<KEYIN> inKeyClass =
(Class<KEYIN>) TypeExtractor.getParameterType(Reducer.class, reducer.getClass(), 0);
TypeSerializer<KEYIN> keySerializer =View on GitHub (pinned to 2f3c205e92)
Solutions
- Pass a valid JobConf (new JobConf() is acceptable if you have no Hadoop config to carry over).
- Prefer the one-arg constructor HadoopReducerWrappedFunction(reducer) which internally supplies a fresh JobConf.
- Guard the caller: if (conf == null) conf = new JobConf(); before constructing the wrapper.
Example fix
// before new HadoopReducerWrappedFunction<>(reducer, null); // after JobConf conf = (conf == null) ? new JobConf() : conf; new HadoopReducerWrappedFunction<>(reducer, conf);
Defensive patterns
Strategy: validation
Validate before calling
JobConf safe = (conf != null) ? conf : new JobConf(); new HadoopReducerWrappedFunction<>(reducer, safe);
Type guard
// guard the conf before constructing if (conf == null) conf = new JobConf();
Prevention
- Prefer the one-arg constructor that supplies a default JobConf.
- Centralize JobConf creation so a single non-null instance is shared.
- Treat null config as a bug at the source, not at the wrapper boundary.
When it happens
Trigger: Calling new HadoopReducerWrappedFunction(reducer, null) directly, or a builder/factory that forwards a conf variable that was never initialized.
Common situations: Sharing a JobConf across operators where one branch left it null; refactoring that introduced a code path bypassing the default JobConf creation; tests constructing the wrapper manually without a conf.
Related errors
- Reducer may not be null.
- The collection contains a null element
- The collection contains a null element
- Hadoop input split must not be null
- Hadoop JobConf must not be null when input split is configur
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/a759280dc608ccf0.
Report an issue: GitHub.