{"record":{"id":"3d80453fd7b184e8","repo":"apache/flink","slug":"mapper-may-not-be-null","errorCode":null,"errorMessage":"Mapper may not be null.","messagePattern":"Mapper 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/HadoopMapFunction.java","lineNumber":77,"sourceCode":"    /**\n     * Maps a Hadoop Mapper (mapred API) to a Flink FlatMapFunction.\n     *\n     * @param hadoopMapper The Hadoop Mapper to wrap.\n     */\n    public HadoopMapFunction(Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopMapper) {\n        this(hadoopMapper, new JobConf());\n    }\n\n    /**\n     * Maps a Hadoop Mapper (mapred API) to a Flink FlatMapFunction. The Hadoop Mapper is configured\n     * with the provided JobConf.\n     *\n     * @param hadoopMapper The Hadoop Mapper to wrap.\n     * @param conf The JobConf that is used to configure the Hadoop Mapper.\n     */\n    public HadoopMapFunction(Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> hadoopMapper, JobConf conf) {\n        if (hadoopMapper == null) {\n            throw new NullPointerException(\"Mapper may not be null.\");\n        }\n        if (conf == null) {\n            throw new NullPointerException(\"JobConf may not be null.\");\n        }\n\n        this.mapper = hadoopMapper;\n        this.jobConf = conf;\n    }\n\n    @PublicEvolving\n    @Override\n    public void open(OpenContext openContext) throws Exception {\n        super.open(openContext);\n        this.mapper.configure(jobConf);\n\n        this.reporter = new HadoopDummyReporter();\n        this.outputCollector = new HadoopOutputCollector<KEYOUT, VALUEOUT>();\n    }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-connectors/flink-hadoop-compatibility/src/main/java/org/apache/flink/hadoopcompatibility/mapred/HadoopMapFunction.java#L59-L95","documentation":"Thrown by the HadoopMapFunction constructor when the wrapped Hadoop mapred Mapper argument is null. This is a hard precondition: a null mapper cannot be serialized or executed, so construction fails fast with a NullPointerException rather than failing later during open()/flatMap().","triggerScenarios":"Produced when new HadoopMapFunction(hadoopMapper, conf) (or the single-arg overload that delegates to it) is called with hadoopMapper == null — e.g. a mapper field that was never initialized, a factory returning null, or test wiring that passes null.","commonSituations":"A Mapper field left null due to a wiring/injection bug; a factory method that can return null under some conditions; copy-paste constructor calls passing the wrong (null) reference; test scaffolding that forgets to set the mapper.","solutions":["Ensure the Mapper passed to HadoopMapFunction is non-null and fully constructed.","If a mapper factory can return null, guard it and fail or supply a default mapper instead.","In tests, instantiate a real or stub Mapper rather than passing null.","Add a null-check at the call site with a clear message before constructing the wrapper."],"exampleFix":"// before\nMapper mapper = mapperFactory.get(); // may be null\nnew HadoopMapFunction(mapper, conf);\n// after — guard against null\nMapper mapper = mapperFactory.get();\nif (mapper == null) throw new IllegalStateException(\"mapperFactory returned null\");\nnew HadoopMapFunction(mapper, conf);","handlingStrategy":"validation","validationCode":"java.util.Objects.requireNonNull(hadoopMapper, \"Hadoop Mapper must not be null\");\nnew HadoopMapFunction(hadoopMapper, conf);","typeGuard":"hadoopMapper != null","tryCatchPattern":null,"preventionTips":["Guard the mapper reference with Objects.requireNonNull before constructing.","Ensure mapper factories never return null.","In tests, instantiate a real or stub Mapper.","Fail loud at wiring time rather than relying on the constructor NPE."],"tags":["hadoop","mapred","validation","constructor","mapper"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}