{"record":{"id":"573729ab29454f77","repo":"apache/hadoop","slug":"expected-edits-or-record","errorCode":null,"errorMessage":"expected </EDITS> or </RECORD>","messagePattern":"expected </EDITS> or </RECORD>","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":205,"sourceCode":"      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:\n      if (!name.equals(\"OPCODE\")) {\n        throw new InvalidXmlException(\"expected </OPCODE>\");\n      }\n      opCode = FSEditLogOpCodes.valueOf(str);\n      state = ParseState.EXPECT_DATA;\n      break;\n    case EXPECT_DATA:\n      throw new InvalidXmlException(\"expected <DATA/>\");\n    case HANDLE_DATA:\n      stanza.setValue(str);\n      if (stanzaStack.empty()) {\n        if (!name.equals(\"DATA\")) {\n          throw new InvalidXmlException(\"expected </DATA>\");\n        }\n        state = ParseState.EXPECT_RECORD;","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L187-L223","documentation":"Thrown from endElement() in EXPECT_RECORD state: at the top level of the document (between two <RECORD> elements, or where </EDITS> should close the file) a closing tag other than </RECORD> or </EDITS> appeared. The format only allows a flat sequence of <RECORD> elements between the version header and </EDITS>; any other element at that depth is rejected.","triggerScenarios":"A stray closing tag between records, e.g. a leftover </RECORDS> after records were wrapped in a container element, or any orphan close tag left by splicing XML fragments at top level. startElement in this state throws a different message, so this specific text means an unexpected close at record level.","commonSituations":"Concatenating or splicing oev XML outputs with sed/awk leaving orphan close tags; wrapping records in a made-up container element; renaming <EDITS> in the footer but not the header.","solutions":["Strip any tags between </RECORD> and the next <RECORD> other than the single final </EDITS>.","If records were wrapped in another element (e.g. <RECORDS>), remove the wrapper — only a flat record list is legal.","Rebuild the file by concatenating whole <RECORD>...</RECORD> blocks inside one <EDITS>...</EDITS> envelope.","When in doubt, regenerate the XML from the binary edit log with hdfs oev."],"exampleFix":"// before\n<EDITS><EDITS_VERSION>-63</EDITS_VERSION>\n<RECORDS>\n  <RECORD>...</RECORD>\n</RECORDS>\n</EDITS>\n\n// after\n<EDITS><EDITS_VERSION>-63</EDITS_VERSION>\n  <RECORD>...</RECORD>\n</EDITS>","handlingStrategy":"try-catch","validationCode":"private static boolean flatRecordList(Path p) throws IOException {\n  // top level between records must contain only <RECORD> opens and the final </EDITS>\n  List<String> lines = Files.readAllLines(p, StandardCharsets.UTF_8);\n  for (String l : lines) {\n    String t = l.trim();\n    if (t.startsWith(\"</\") && !t.startsWith(\"</RECORD>\") && !t.startsWith(\"</EDITS>\")\n        && !t.startsWith(\"</EDITS_VERSION>\")) return false;\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  // stray close tag at top level; re-splice whole RECORD blocks only\n  LOG.error(\"Illegal top-level tag in edits XML: {}\", e.getMessage());\n}","preventionTips":["Splice only whole <RECORD>...</RECORD> blocks inside one <EDITS> envelope.","Do not invent wrapper elements around records.","After any sed/awk surgery, diff the tag balance (count opens vs closes per name)."],"tags":["hdfs","offline-edits-viewer","oev","edit-log","xml","state-machine"],"backgroundTag":"malformed-xml-input","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}