{"record":{"id":"e86b38f1c32d7ab9","repo":"apache/hadoop","slug":"unexpected-xml-event-ev","errorCode":null,"errorMessage":"Unexpected XML event {ev}","messagePattern":"Unexpected XML event (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java","lineNumber":396,"sourceCode":"          String key = ev.asStartElement().getName().getLocalPart();\n          for (String terminator : terminators) {\n            if (terminator.equals(key)) {\n              return;\n            }\n          }\n          events.nextEvent();\n          Node node = new Node();\n          parent.addChild(key, node);\n          loadNodeChildrenHelper(node, expected, new String[0]);\n          break;\n        case XMLEvent.CHARACTERS:\n          String val = XMLUtils.\n              unmangleXmlString(ev.asCharacters().getData(), false);\n          parent.setVal(parent.getVal() + val);\n          events.nextEvent();\n          break;\n        case XMLEvent.ATTRIBUTE:\n          throw new IOException(\"Unexpected XML event \" + ev);\n        default:\n          // Ignore other event types like comment, etc.\n          if (LOG.isTraceEnabled()) {\n            LOG.trace(\"Skipping XMLEvent \" + ev);\n          }\n          events.nextEvent();\n          break;\n        }\n      } catch (XMLStreamException e) {\n        throw new IOException(\"Expecting \" + expected +\n            \", but got XMLStreamException\", e);\n      }\n    }\n  }\n\n  /**\n   * Load a subtree of the XML into a Node structure.\n   * We will keep consuming XML events until we exit the current subtree.","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L378-L414","documentation":"loadNodeChildrenHelper builds the in-memory Node tree for a subtree and handles only START_ELEMENT, CHARACTERS, and ignorable event types; an ATTRIBUTE event throws this IOException. It is the subtree-loading twin of the attribute check in expectTag: oiv XML never uses attributes, so any attribute inside a section subtree marks input produced or rewritten by something other than the oiv XML processor.","triggerScenarios":"ReverseXML on XML whose elements carry attributes anywhere within a section subtree - e.g. <inode type=\"FILE\"> - after a pretty-printer, custom exporter, or hand authoring introduced them.","commonSituations":"Transform pipelines (XSLT, JSON-to-XML converters) between dump and reconstruction; hand-authored entries modeled on attribute-style schemas.","solutions":["Convert all attributes to child elements holding the value as text","Regenerate the XML with `hdfs oiv -p XML` from the source fsimage","Gate the pipeline: xmllint --xpath 'count(//*[attribute::*])' img.xml must return 0"],"exampleFix":"<!-- before -->\n<inode type=\"FILE\"><name>part-00000</name></inode>\n\n<!-- after -->\n<inode><type>FILE</type><name>part-00000</name></inode>","handlingStrategy":"validation","validationCode":"n=$(xmllint --xpath 'count(//*[attribute::*])' fsimage.xml 2>/dev/null)\n[ \"$n\" = \"0\" ] || { echo \"$n attribute(s) present - oiv schema uses child elements only\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Convert external formats to oiv's element-with-text style, not attributes","Add an attribute-count assertion as a pipeline gate before ReverseXML","Avoid pretty-printers/exporters that restyle markup"],"tags":["hdfs","reversexml","xml-attributes","fsimage"],"backgroundTag":"unexpected-xml-attribute","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}