apache/flink · error · NullPointerException
Reducer may not be null.
Error message
Reducer may not be null.
What it means
Thrown by the HadoopReducerWrappedFunction constructor when wrapping a Hadoop mapred Reducer into a Flink GroupReduceFunction. The wrapper requires a non-null Reducer because the whole point of the class is to delegate reduce() calls to it; a null reducer has no behavior to invoke. It surfaces a caller bug (passing null) rather than a runtime state problem.
Source
Thrown at flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/HadoopReducerWrappedFunction.java:90
/**
* Maps a Hadoop Reducer (mapred API) to a non-combinable Flink GroupReduceFunction.
*
* @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>();View on GitHub (pinned to 2f3c205e92)
Solutions
- Ensure the org.apache.hadoop.mapred.Reducer instance is instantiated and non-null before passing it to the constructor.
- If loading the reducer class from config, validate the configured class name resolves and instantiate it inside a try/catch, propagating a clear error before reaching the wrapper.
- Prefer using HadoopRedistributeFunction.wrap/reduce helpers from flink-hadoop-compatibility which build the wrapper for you.
Example fix
// before
new HadoopReducerWrappedFunction<>(nullReducer, jobConf);
// after
Reducer<KIn,VIn,KOut,VOut> reducer =
(Reducer<KIn,VIn,KOut,VOut>) jobConf.getClass("mapred.reducer.class", null, Reducer.class)
.getDeclaredConstructor().newInstance();
if (reducer == null) {
throw new IllegalArgumentException("mapred.reducer.class not set in JobConf");
}
new HadoopReducerWrappedFunction<>(reducer, jobConf); Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(hadoopReducer, "Reducer must not be null"); new HadoopReducerWrappedFunction<>(hadoopReducer, conf);
Type guard
// java: null check is the guard
Reducer<KIn,VIn,KOut,VOut> r = hadoopReducer;
if (r == null) throw new IllegalArgumentException("reducer is null"); Prevention
- Instantiate the Reducer in one place and null-check immediately after.
- Prefer HadoopRedistributeFunction helper APIs that build the wrapper for you.
- Never load reducer classes reflectively without checking the result for null.
When it happens
Trigger: Constructing new HadoopReducerWrappedFunction(null, conf) or new HadoopReducerWrappedFunction(null) (the one-arg overload delegates to the two-arg with a new JobConf). Happens when a Reducer instance is created via reflection/config that silently returned null.
Common situations: HadoopCompatibility wrappers built dynamically from a JobConf where conf.getClass(...).newInstance() failed or the configured reducer class name was wrong and resolved to null; migration code that conditionally supplies a reducer.
Related errors
- JobConf 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/0fc9a525080b2196.
Report an issue: GitHub.