{"record":{"id":"0fc9a525080b2196","repo":"apache/flink","slug":"reducer-may-not-be-null","errorCode":null,"errorMessage":"Reducer may not be null.","messagePattern":"Reducer may not be null\\.","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/HadoopReducerWrappedFunction.java","lineNumber":90,"sourceCode":"    /**\n     * Maps a Hadoop Reducer (mapred API) to a non-combinable Flink GroupReduceFunction.\n     *\n     * @param hadoopReducer The Hadoop Reducer to wrap.\n     */\n    public HadoopReducerWrappedFunction(Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopReducer) {\n        this(hadoopReducer, new JobConf());\n    }\n\n    /**\n     * Maps a Hadoop Reducer (mapred API) to a non-combinable Flink GroupReduceFunction.\n     *\n     * @param hadoopReducer The Hadoop Reducer to wrap.\n     * @param conf The JobConf that is used to configure the Hadoop Reducer.\n     */\n    public HadoopReducerWrappedFunction(\n            Reducer<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopReducer, JobConf conf) {\n        if (hadoopReducer == null) {\n            throw new NullPointerException(\"Reducer may not be null.\");\n        }\n        if (conf == null) {\n            throw new NullPointerException(\"JobConf may not be null.\");\n        }\n\n        this.reducer = hadoopReducer;\n        this.jobConf = conf;\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @PublicEvolving\n    @Override\n    public void open(OpenContext openContext) throws Exception {\n        super.open(openContext);\n        this.reducer.configure(jobConf);\n\n        this.reporter = new HadoopDummyReporter();\n        this.reduceCollector = new HadoopOutputCollector<KEYOUT, VALUEOUT>();","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/HadoopReducerWrappedFunction.java#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew HadoopReducerWrappedFunction<>(nullReducer, jobConf);\n// after\nReducer<KIn,VIn,KOut,VOut> reducer =\n    (Reducer<KIn,VIn,KOut,VOut>) jobConf.getClass(\"mapred.reducer.class\", null, Reducer.class)\n        .getDeclaredConstructor().newInstance();\nif (reducer == null) {\n    throw new IllegalArgumentException(\"mapred.reducer.class not set in JobConf\");\n}\nnew HadoopReducerWrappedFunction<>(reducer, jobConf);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(hadoopReducer, \"Reducer must not be null\");\nnew HadoopReducerWrappedFunction<>(hadoopReducer, conf);","typeGuard":"// java: null check is the guard\nReducer<KIn,VIn,KOut,VOut> r = hadoopReducer;\nif (r == null) throw new IllegalArgumentException(\"reducer is null\");","tryCatchPattern":null,"preventionTips":["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."],"tags":["hadoop-compatibility","mapred","null-check","constructor"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}