{"record":{"id":"a42c742c26abc115","repo":"apache/hadoop","slug":"not-expecting-anything-after-edits","errorCode":null,"errorMessage":"not expecting anything after </EDITS>","messagePattern":"not expecting anything after </EDITS>","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":177,"sourceCode":"        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\");\n      }\n      stanza = new Stanza();\n      state = ParseState.HANDLE_DATA;\n      break;\n    case HANDLE_DATA:\n      Stanza parent = stanza;\n      Stanza child = new Stanza();\n      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) {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L159-L195","documentation":"After the closing </EDITS> is processed the state machine is in ParseState.EXPECT_END and the document is logically finished. If any further start-element event arrives, the handler throws InvalidXmlException('not expecting anything after </EDITS>') — the loader accepts exactly one edits document and no trailing content.","triggerScenarios":"Two edits documents concatenated into one file; comments-with-elements, processing artifacts, or appended XML after the closing tag; a wrapper element closed after </EDITS>.","commonSituations":"Appending dumps (cat a.xml b.xml > all.xml); redirect mistakes appending a second run's output; files edited to add a footer element.","solutions":["Split the file so each document contains exactly one <EDITS>...</EDITS> and process them separately.","Delete everything after the first </EDITS> line.","When concatenating outputs programmatically, parse-and-merge records instead of concatenating raw XML."],"exampleFix":"<!-- before -->\n<EDITS>...</EDITS>\n<EDITS>...</EDITS>\n\n<!-- after: two files, one document each -->\n# split -p '<\\/EDITS>' all.xml part_ && hdfs oev -i part_00 -o a.xml -p xml","handlingStrategy":"try-catch","validationCode":"// Reject files with more than one <EDITS> root-level occurrence before loading\nString content = Files.readString(Path.of(file));\nint first = content.indexOf(\"</EDITS>\");\nif (first >= 0 && content.indexOf(\"<EDITS\", first) >= 0) {\n  throw new IOException(file\n      + \" contains content after </EDITS>; split into one document per file\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  if (e.getMessage().contains(\"after </EDITS>\")) {\n    System.err.println(\"Trailing content after the edits document; split or trim \"\n        + \"the file so it ends right after </EDITS>\");\n  }\n}","preventionTips":["Never concatenate edits XML files; process each document separately.","Use 'set -o noclobber' and distinct output names so redirected oev output is not appended to."],"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-23T01:17:44.959Z"}