{"record":{"id":"fedc4ace845926bb","repo":"apache/hadoop","slug":"you-must-put-edits-version-at-the-top-of-the-xml","errorCode":null,"errorMessage":"you must put <EDITS_VERSION> at the top of the XML file! Got tag {} instead","messagePattern":"you must put <EDITS_VERSION> at the top of the XML file! Got tag (.+?) instead","errorType":"validation","errorClass":"InvalidXmlException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java","lineNumber":146,"sourceCode":"      throw new InvalidXmlException(\"expecting </EDITS>\");\n    }\n  }\n  \n  @Override\n  public void startElement (String uri, String name,\n      String qName, Attributes atts) {\n    switch (state) {\n    case EXPECT_EDITS_TAG:\n      if (!name.equals(\"EDITS\")) {\n        throw new InvalidXmlException(\"you must put \" +\n            \"<EDITS> at the top of the XML file! \" +\n            \"Got tag \" + name + \" instead\");\n      }\n      state = ParseState.EXPECT_VERSION;\n      break;\n    case EXPECT_VERSION:\n      if (!name.equals(\"EDITS_VERSION\")) {\n        throw new InvalidXmlException(\"you must put \" +\n            \"<EDITS_VERSION> at the top of the XML file! \" +\n            \"Got tag \" + name + \" instead\");\n      }\n      break;\n    case EXPECT_RECORD:\n      if (!name.equals(\"RECORD\")) {\n        throw new InvalidXmlException(\"expected a <RECORD> tag\");\n      }\n      state = ParseState.EXPECT_OPCODE;\n      break;\n    case EXPECT_OPCODE:\n      if (!name.equals(\"OPCODE\")) {\n        throw new InvalidXmlException(\"expected an <OPCODE> tag\");\n      }\n      break;\n    case EXPECT_DATA:\n      if (!name.equals(\"DATA\")) {\n        throw new InvalidXmlException(\"expected a <DATA> tag\");","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L128-L164","documentation":"After the root <EDITS> opens, the state machine moves to EXPECT_VERSION and the next start element must be <EDITS_VERSION> (carrying the edits layout version). Any other tag at that position throws InvalidXmlException demanding <EDITS_VERSION> at the top. The version element is mandatory even in hand-built or fixture XML files.","triggerScenarios":"An edits XML where <EDITS_VERSION> is missing (first child is directly a <RECORD>) or was renamed/removed during manual editing or XML generation.","commonSituations":"Hand-written test fixtures that skip the version element; XSLT/serialization pipelines that drop single-value children; trimming files and accidentally removing the header record.","solutions":["Insert <EDITS_VERSION>...</EDITS_VERSION> as the first child of <EDITS>, e.g. -64 for recent layout versions.","Prefer generating fixtures with 'hdfs oev -p xml' so the header is always correct.","Copy the version value from an authentic dump of the same Hadoop version rather than guessing."],"exampleFix":"<!-- before -->\n<EDITS><RECORD>...</RECORD></EDITS>\n\n<!-- after -->\n<EDITS><EDITS_VERSION>-64</EDITS_VERSION><RECORD>...</RECORD></EDITS>","handlingStrategy":"validation","validationCode":"try (XMLStreamReader r = XMLInputFactory.newFactory()\n        .createXMLStreamReader(new FileInputStream(file))) {\n  r.next();                    // <EDITS>\n  r.nextTag();                 // first child must be EDITS_VERSION\n  if (!\"EDITS_VERSION\".equals(r.getLocalName())) {\n    throw new IOException(\"First child of <EDITS> must be <EDITS_VERSION>, found <\"\n        + r.getLocalName() + \">\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  if (e.getMessage().contains(\"<EDITS_VERSION>\")) {\n    throw new IOException(\"Missing <EDITS_VERSION> header; regenerate the XML \"\n        + \"with oev or copy the element from a real dump.\", e);\n  }\n  throw e;\n}","preventionTips":["Generate fixtures with oev so the version header is always present and correct.","When templating XML, assert the header element survived the template engine."],"tags":["hadoop","hdfs","offline-edits-viewer","xml","parsing"],"backgroundTag":"malformed-xml-document","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}