{"record":{"id":"0e55f8c78ca6172e","repo":"apache/hadoop","slug":"expected-edits-version","errorCode":null,"errorMessage":"expected </EDITS_VERSION>","messagePattern":"expected </EDITS_VERSION>","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":190,"sourceCode":"      stanzaStack.push(parent);\n      stanza = child;\n      parent.addChild(name, child);\n      break;\n    case EXPECT_END:\n      throw new InvalidXmlException(\"not expecting anything after </EDITS>\");\n    }\n  }\n  \n  @Override\n  public void endElement (String uri, String name, String qName) {\n    String str = XMLUtils.unmangleXmlString(cbuf.toString(), false).trim();\n    cbuf = new StringBuilder();\n    switch (state) {\n    case EXPECT_EDITS_TAG:\n      throw new InvalidXmlException(\"expected <EDITS/>\");\n    case EXPECT_VERSION:\n      if (!name.equals(\"EDITS_VERSION\")) {\n        throw new InvalidXmlException(\"expected </EDITS_VERSION>\");\n      }\n      try {\n        int version = Integer.parseInt(str);\n        visitor.start(version);\n      } catch (IOException e) {\n        // Can't throw IOException from a SAX method, sigh.\n        throw new RuntimeException(e);\n      }\n      state = ParseState.EXPECT_RECORD;\n      break;\n    case EXPECT_RECORD:\n      if (name.equals(\"EDITS\")) {\n        state = ParseState.EXPECT_END;\n      } else if (!name.equals(\"RECORD\")) {\n        throw new InvalidXmlException(\"expected </EDITS> or </RECORD>\");\n      }\n      break;\n    case EXPECT_OPCODE:","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L172-L208","documentation":"Thrown from endElement() when the parser is in EXPECT_VERSION state (right after <EDITS> opened) and the element being closed is not EDITS_VERSION. The loader demands that the first child of <EDITS> be exactly <EDITS_VERSION>number</EDITS_VERSION>, whose text is parsed as an int layout version (e.g. -63) and passed to visitor.start(). A misspelled, wrongly-cased, or namespace-prefixed version tag breaks this check.","triggerScenarios":"An XML edits file in which the element inside <EDITS> is not named exactly EDITS_VERSION (e.g. <EDITS-VERSION>, <edits_version>, or a prefixed tag), so name.equals(\"EDITS_VERSION\") fails on close. Also reachable when header elements are reordered or renamed by naive XML rewriters.","commonSituations":"Hand-editing or programmatically regenerating oev XML and getting the header tag wrong; XSLT transforms or pretty-printers that rename or namespace elements; merging output from a different tool version.","solutions":["Make the first child of <EDITS> exactly <EDITS_VERSION>-63</EDITS_VERSION> (or the layout version your target format expects), spelled identically on open and close.","Regenerate the file with hdfs oev -i <binary edits> -p XML -o edits.xml instead of editing it.","Remove namespace prefixes or attributes from the header tags; the state machine compares raw local names."],"exampleFix":"// before\n<EDITS>\n  <EDITS-VERSION>-63</EDITS-VERSION>\n  ...\n\n// after\n<EDITS>\n  <EDITS_VERSION>-63</EDITS_VERSION>\n  ...","handlingStrategy":"try-catch","validationCode":"private static boolean hasValidHeader(File f) throws IOException {\n  byte[] b = Files.readAllBytes(f.toPath());\n  String head = new String(b, 0, (int) Math.min(4096, b.length), StandardCharsets.UTF_8).trim();\n  return head.matches(\"(?s)\\\\A<\\\\?xml[^>]*\\\\?>\\\\s*<EDITS>\\\\s*<EDITS_VERSION>-?\\\\d+</EDITS_VERSION>.*\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  // Header tag wrong: expected first child <EDITS_VERSION>nn</EDITS_VERSION>\n  throw new IOException(\"Bad OEV XML header in \" + file + \": \" + e.getMessage(), e);\n}","preventionTips":["Generate header tags programmatically from the same constants oev uses; never retype them.","Reject files whose second element is not exactly EDITS_VERSION before conversion.","Avoid XSLT/pretty-printers that rename or namespace elements in edits XML."],"tags":["hdfs","offline-edits-viewer","oev","edit-log","xml","header-validation"],"backgroundTag":"malformed-xml-input","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}