{"record":{"id":"bd650ce473112499","repo":"apache/hadoop","slug":"record-writer-not-set-for-filterrecordwriter","errorCode":null,"errorMessage":"Record Writer not set for FilterRecordWriter","messagePattern":"Record Writer not set for FilterRecordWriter","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/lib/FilterOutputFormat.java","lineNumber":97,"sourceCode":"    public FilterRecordWriter() throws IOException {\n      rawWriter = null;\n    }\n\n    public FilterRecordWriter(RecordWriter<K,V> rawWriter)  throws IOException {\n      this.rawWriter = rawWriter;\n    }\n\n    public void close(Reporter reporter) throws IOException {\n      getRawWriter().close(reporter);\n    }\n\n    public void write(K key, V value) throws IOException {\n      getRawWriter().write(key, value);\n    }\n    \n    private RecordWriter<K,V> getRawWriter() throws IOException {\n      if (rawWriter == null) {\n        throw new IOException (\"Record Writer not set for FilterRecordWriter\");\n      }\n      return rawWriter;\n    }\n  }\n\n}\n","sourceCodeStart":79,"sourceCodeEnd":104,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/lib/FilterOutputFormat.java#L79-L104","documentation":"FilterRecordWriter is a convenience RecordWriter wrapper whose write() and close() delegate to the RecordWriter stored in its protected rawWriter field. getRawWriter() throws this IOException when write() or close() is called before a subclass assigned rawWriter. It indicates the wrapper was created but never given the underlying writer it forwards to.","triggerScenarios":"Extending FilterRecordWriter (the inner class of FilterOutputFormat) without assigning rawWriter, then the framework calls write() during the map/reduce phase or close() at task commit. A subtler variant: a subclass that creates rawWriter lazily on first write(), but the task writes zero records so close() runs first and hits the null rawWriter.","commonSituations":"Lazy-writer patterns (like LazyOutputFormat's LazyRecordWriter) copied without the null guard in close(); wrapper writers that conditionally create the underlying writer and skip creation when no data was written.","solutions":["Assign rawWriter in the constructor of your FilterRecordWriter subclass","If rawWriter is created lazily, override close() to guard: if (rawWriter != null) rawWriter.close(reporter);","Verify every code path that can call write()/close() has initialized the delegate first"],"exampleFix":"// before: close() NPE-path -> IOException \"Record Writer not set for FilterRecordWriter\"\npublic void close(Reporter reporter) throws IOException {\n  getRawWriter().close(reporter); // rawWriter null when nothing was written\n}\n\n// after: guard the delegate\npublic void close(Reporter reporter) throws IOException {\n  if (rawWriter != null) {\n    rawWriter.close(reporter);\n  }\n}","handlingStrategy":"validation","validationCode":"// guard every delegation in a FilterRecordWriter subclass\npublic void close(Reporter reporter) throws IOException {\n  if (rawWriter != null) {\n    rawWriter.close(reporter);\n  }\n}\npublic void write(K key, V value) throws IOException {\n  if (rawWriter == null) throw new IOException(\"writer not initialized for this path\");\n  rawWriter.write(key, value);\n}","typeGuard":null,"tryCatchPattern":"try {\n  writer.close(reporter);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"not set for FilterRecordWriter\")) {\n    LOG.warn(\"no underlying writer; nothing was written through this wrapper\");\n    return;\n  }\n  throw e;\n}","preventionTips":["Initialize rawWriter in the constructor whenever possible","For lazily-created writers, always pair the lazy creation with a null guard in close()","Cover the zero-records path in unit tests — it is exactly where close() hits a null delegate"],"tags":["hadoop","mapreduce","recordwriter","filter-outputformat","delegate"],"backgroundTag":"unconfigured-delegate","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}