{"record":{"id":"dd95bc726258f41a","repo":"apache/hadoop","slug":"error-serializing","errorCode":null,"errorMessage":"Error serializing {}","messagePattern":"Error serializing (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/record/CsvRecordOutput.java","lineNumber":44,"sourceCode":"import java.io.UnsupportedEncodingException;\n\nimport org.apache.hadoop.classification.InterfaceAudience;\nimport org.apache.hadoop.classification.InterfaceStability;\n\n/**\n * @deprecated Replaced by <a href=\"http://hadoop.apache.org/avro/\">Avro</a>.\n */\n@Deprecated\n@InterfaceAudience.Public\n@InterfaceStability.Stable\npublic class CsvRecordOutput implements RecordOutput {\n\n  private PrintStream stream;\n  private boolean isFirst = true;\n    \n  private void throwExceptionOnError(String tag) throws IOException {\n    if (stream.checkError()) {\n      throw new IOException(\"Error serializing \"+tag);\n    }\n  }\n \n  private void printCommaUnlessFirst() {\n    if (!isFirst) {\n      stream.print(\",\");\n    }\n    isFirst = false;\n  }\n    \n  /** Creates a new instance of CsvRecordOutput */\n  public CsvRecordOutput(OutputStream out) {\n    try {\n      stream = new PrintStream(out, true, \"UTF-8\");\n    } catch (UnsupportedEncodingException ex) {\n      throw new RuntimeException(ex);\n    }\n  }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-streaming/src/main/java/org/apache/hadoop/record/CsvRecordOutput.java#L26-L62","documentation":"CsvRecordOutput (the deprecated org.apache.hadoop.record CSV serialization used by legacy Hadoop streaming/record apps) calls PrintStream.checkError() after writing each field; if the underlying PrintStream has entered the error state, it throws IOException 'Error serializing <tag>'. PrintStream swallows IOExceptions internally, so this is the only way the writer surfaces a broken output stream.","triggerScenarios":"Any Write* call (WriteString/WriteInt/WriteBuffer/...) after the wrapped OutputStream has failed: the sink was already closed, the disk is full, the downstream socket or pipe reader died, or the stream was constructed with a bad OutputStream.","commonSituations":"Writing CSV records to a socket whose peer closed first, writing to a closed file after a previous failure, or long-lived streams on full disks. The tag in the message tells you which field was being written when the failure was detected, not the root cause — the real cause must be inferred from the environment.","solutions":["Check the health of the underlying OutputStream (is it closed? is the peer alive? is the disk full?) — the field tag is only where the error surfaced","Do not reuse a CsvRecordOutput after this IOException; create a new one on a fresh stream","Close streams deterministically (RecordWriter.close()) and handle that close's exceptions","Migrate off org.apache.hadoop.record entirely — it is deprecated in favor of Avro or Writable serialization"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { out.WriteString(tag, s); } catch (IOException ioe) { /* ioe.getMessage() names the tag; abort the record, close and discard the writer, surface the underlying stream problem */ }","preventionTips":["Open one CsvRecordOutput per record batch on a stream you own; never reuse after an IOException","Guarantee the peer stays alive until RecordWriter.close() completes (socket readers, downstream consumers)","Check disk space and stream state in monitoring since PrintStream swallows the original error","Plan a migration to Avro/Writable; org.apache.hadoop.record is deprecated"],"tags":["hadoop-record","csv","serialization","deprecated","io-stream"],"backgroundTag":"stream-write-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}