apache/hadoop · error · InvalidXmlException

not expecting anything after </EDITS>

Error message

not expecting anything after </EDITS>

What it means

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.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java:177

        throw new InvalidXmlException("expected an <OPCODE> tag");
      }
      break;
    case EXPECT_DATA:
      if (!name.equals("DATA")) {
        throw new InvalidXmlException("expected a <DATA> tag");
      }
      stanza = new Stanza();
      state = ParseState.HANDLE_DATA;
      break;
    case HANDLE_DATA:
      Stanza parent = stanza;
      Stanza child = new Stanza();
      stanzaStack.push(parent);
      stanza = child;
      parent.addChild(name, child);
      break;
    case EXPECT_END:
      throw new InvalidXmlException("not expecting anything after </EDITS>");
    }
  }
  
  @Override
  public void endElement (String uri, String name, String qName) {
    String str = XMLUtils.unmangleXmlString(cbuf.toString(), false).trim();
    cbuf = new StringBuilder();
    switch (state) {
    case EXPECT_EDITS_TAG:
      throw new InvalidXmlException("expected <EDITS/>");
    case EXPECT_VERSION:
      if (!name.equals("EDITS_VERSION")) {
        throw new InvalidXmlException("expected </EDITS_VERSION>");
      }
      try {
        int version = Integer.parseInt(str);
        visitor.start(version);
      } catch (IOException e) {

View on GitHub (pinned to 2add963021)

Solutions

  1. Split the file so each document contains exactly one <EDITS>...</EDITS> and process them separately.
  2. Delete everything after the first </EDITS> line.
  3. When concatenating outputs programmatically, parse-and-merge records instead of concatenating raw XML.

Example fix

<!-- before -->
<EDITS>...</EDITS>
<EDITS>...</EDITS>

<!-- after: two files, one document each -->
# split -p '<\/EDITS>' all.xml part_ && hdfs oev -i part_00 -o a.xml -p xml
Defensive patterns

Strategy: try-catch

Validate before calling

// Reject files with more than one <EDITS> root-level occurrence before loading
String content = Files.readString(Path.of(file));
int first = content.indexOf("</EDITS>");
if (first >= 0 && content.indexOf("<EDITS", first) >= 0) {
  throw new IOException(file
      + " contains content after </EDITS>; split into one document per file");
}

Try / catch

try {
  loader.loadEdits();
} catch (InvalidXmlException e) {
  if (e.getMessage().contains("after </EDITS>")) {
    System.err.println("Trailing content after the edits document; split or trim "
        + "the file so it ends right after </EDITS>");
  }
}

Prevention

When it happens

Trigger: 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>.

Common situations: Appending dumps (cat a.xml b.xml > all.xml); redirect mistakes appending a second run's output; files edited to add a footer element.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/a42c742c26abc115. Report an issue: GitHub.