apache/hadoop · error · IOException
SAX error: {}
Error message
SAX error: {} What it means
XmlEditsVisitor's constructor emits startDocument() and the opening <EDITS> element through the transformer handler; this IOException wraps a SAXException from those first callbacks. It means the serialization pipeline failed at the very start of output — usually an unusable output stream (the StreamResult target) rather than bad edit-log data.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/XmlEditsVisitor.java:80
this.out = out;
try {
factory = org.apache.hadoop.util.XMLUtils.newSecureSAXTransformerFactory();
TransformerHandler handler = factory.newTransformerHandler();
handler.getTransformer().setOutputProperty(OutputKeys.METHOD, "xml");
handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, "UTF-8");
handler.getTransformer().setOutputProperty(OutputKeys.INDENT, "yes");
handler.getTransformer().setOutputProperty(XML_INDENTATION_PROP,
XML_INDENTATION_NUM);
handler.getTransformer().setOutputProperty(OutputKeys.STANDALONE, "yes");
handler.setResult(new StreamResult(out));
contentHandler = handler;
contentHandler.startDocument();
contentHandler.startElement("", "", "EDITS", new AttributesImpl());
} catch (TransformerConfigurationException e) {
throw new IOException("SAXTransformer error: " + e.getMessage());
} catch (SAXException e) {
throw new IOException("SAX error: " + e.getMessage());
}
}
/**
* Start visitor (initialization)
*/
@Override
public void start(int version) throws IOException {
try {
contentHandler.startElement("", "", "EDITS_VERSION", new AttributesImpl());
StringBuilder bld = new StringBuilder();
bld.append(version);
addString(bld.toString());
contentHandler.endElement("", "", "EDITS_VERSION");
}
catch (SAXException e) {
throw new IOException("SAX error: " + e.getMessage());
}View on GitHub (pinned to 2add963021)
Solutions
- Verify the OutputStream is open and writable before constructing the visitor (write and reset a test byte).
- Open the output file and construct the visitor right before use, not long-lived across failures.
- Build a fresh XmlEditsVisitor per output file; never reuse instances across runs.
- If it persists on a valid stream, investigate the JAXP environment (see the SAXTransformer error).
Defensive patterns
Strategy: validation
Validate before calling
private static OutputStream openWritable(File f) throws IOException {
OutputStream out = new FileOutputStream(f);
out.write(' '); // probe write
out.flush();
new RandomAccessFile(f, "rw").setLength(0); // reset probe
return out;
} Try / catch
try {
visitor = new XmlEditsVisitor(out);
} catch (IOException e) {
// constructor failed writing <EDITS>; check stream/disk before retrying with a fresh one
out.close();
throw e;
} Prevention
- Open the output stream immediately before constructing the visitor.
- Never pass an already-closed stream as the visitor target.
- Construct a fresh visitor per output file; do not pool or reuse.
When it happens
Trigger: new XmlEditsVisitor(out) where the OutputStream passed as StreamResult is already closed, null-wrapped, or fails on first write; a transformer handler left in a bad state from a prior failure.
Common situations: Passing a stream obtained from an already-closed FileOutputStream; reusing a visitor or output target after an earlier error; wrapper streams closed prematurely by application code.
Related errors
- expected <EDITS/>
- can't understand DelegationTokenIdentifier KIND {kind}
- {e}
- Invalid value for FsAction
- expecting </EDITS>
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/a0d7cc9b9672e802.
Report an issue: GitHub.