{"record":{"id":"6a3fcc4531bcf7f7","repo":"apache/hadoop","slug":"saxtransformer-error","errorCode":null,"errorMessage":"SAXTransformer error: {}","messagePattern":"SAXTransformer error: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/XmlEditsVisitor.java","lineNumber":78,"sourceCode":"  public XmlEditsVisitor(OutputStream out)\n      throws IOException {\n    this.out = out;\n    try {\n      factory = org.apache.hadoop.util.XMLUtils.newSecureSAXTransformerFactory();\n      TransformerHandler handler = factory.newTransformerHandler();\n      handler.getTransformer().setOutputProperty(OutputKeys.METHOD, \"xml\");\n      handler.getTransformer().setOutputProperty(OutputKeys.ENCODING, \"UTF-8\");\n      handler.getTransformer().setOutputProperty(OutputKeys.INDENT, \"yes\");\n      handler.getTransformer().setOutputProperty(XML_INDENTATION_PROP,\n              XML_INDENTATION_NUM);\n      handler.getTransformer().setOutputProperty(OutputKeys.STANDALONE, \"yes\");\n      handler.setResult(new StreamResult(out));\n      contentHandler = handler;\n      \n      contentHandler.startDocument();\n      contentHandler.startElement(\"\", \"\", \"EDITS\", new AttributesImpl());\n    } catch (TransformerConfigurationException e) {\n      throw new IOException(\"SAXTransformer error: \" + e.getMessage());\n    } catch (SAXException e) {\n      throw new IOException(\"SAX error: \" + e.getMessage());\n    }\n  }\n\n  /**\n   * Start visitor (initialization)\n   */\n  @Override\n  public void start(int version) throws IOException {\n    try {\n      contentHandler.startElement(\"\", \"\", \"EDITS_VERSION\", new AttributesImpl());\n      StringBuilder bld = new StringBuilder();\n      bld.append(version);\n      addString(bld.toString());\n      contentHandler.endElement(\"\", \"\", \"EDITS_VERSION\");\n    }\n    catch (SAXException e) {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/XmlEditsVisitor.java#L60-L96","documentation":"XmlEditsVisitor serializes edit-log ops to XML through a JAXP SAXTransformerFactory/TransformerHandler pipeline. This IOException wraps a TransformerConfigurationException raised while obtaining or configuring the handler in the constructor (newTransformerHandler plus output properties). It is an environment problem — the JVM's XML transformer could not be instantiated — not an edits-data problem.","triggerScenarios":"Constructing XmlEditsVisitor when javax.xml.transform.TransformerFactory (system property or META-INF/services) resolves to an implementation that cannot supply a TransformerHandler or rejects the requested output properties. Typically conflicting or ancient xalan/xerces jars ahead of the JDK's built-in implementation.","commonSituations":"Launchers that set -Djavax.xml.transform.TransformerFactory=...; applications embedding Hadoop that bundle an old xalan.jar; hardened JVMs or agents that restrict transformer instantiation; unusual JREs without a default transformer.","solutions":["Check for overrides: print System.getProperty(\"javax.xml.transform.TransformerFactory\") — it should be null (JDK default) or a known-good factory.","Prune duplicate/old xalan, xercesImpl and xml-apis jars from the classpath so the JDK implementation wins.","If a specific factory must be set, verify it supports SAXTransformerFactory.FEATURE and newTransformerHandler() before launching.","Reproduce on a stock JDK with a minimal classpath (just the hadoop jars) to confirm the environment is the cause."],"exampleFix":"# before\nexport JAVA_TOOL_OPTIONS=\"-Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl\"\nhdfs oev -i edits -p XML -o out.xml   # old xalan on classpath\n\n# after\nunset JAVA_TOOL_OPTIONS\nhdfs oev -i edits -p XML -o out.xml   # JDK default transformer","handlingStrategy":"try-catch","validationCode":"import javax.xml.transform.*;\n\nprivate static void verifyTransformerFactory() throws IOException {\n  try {\n    SAXTransformerFactory f = (SAXTransformerFactory) TransformerFactory.newInstance();\n    if (!f.getFeature(SAXTransformerFactory.FEATURE)) {\n      throw new IOException(\"Configured TransformerFactory cannot serialize SAX\");\n    }\n    f.newTransformerHandler();  // fail fast with a clear message\n  } catch (ClassCastException | TransformerConfigurationException e) {\n    throw new IOException(\"Bad JAXP setup: check -Djavax.xml.transform.TransformerFactory and classpath\", e);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  visitor = new XmlEditsVisitor(out);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"SAXTransformer error\")) {\n    // environment: fix JAXP factory/classpath instead of retrying\n    throw new IllegalStateException(\"XML transformer misconfigured: \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Do not set javax.xml.transform.TransformerFactory to an implementation lacking SAX support.","Keep exactly one modern JAXP implementation (JDK default) on the classpath; evict old xalan/xerces jars.","Smoke-test new XmlEditsVisitor(out) on a tiny edits file as part of environment validation."],"tags":["hdfs","offline-edits-viewer","xml","jaxp","transformer","classpath"],"backgroundTag":"transformer-configuration-exception","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}