{"record":{"id":"2d56daca93ef3782","repo":"apache/hadoop","slug":"expected-a-record-tag","errorCode":null,"errorMessage":"expected a <RECORD> tag","messagePattern":"expected a <RECORD> tag","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":153,"sourceCode":"    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\");\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();","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L135-L171","documentation":"Once the version element closes, the loader sits in ParseState.EXPECT_RECORD and each subsequent start element must be <RECORD> (or nothing until </EDITS>). Any other element at that position — stray tags between records, misplaced data elements, or a record child leaking outside its parent — throws InvalidXmlException('expected a <RECORD> tag').","triggerScenarios":"An XML edits file containing an unexpected element between records: e.g. text-structural tags introduced by manual merging, a <DATA> block placed directly under <EDITS>, or duplicated/deeply nested record tags from a broken generator.","commonSituations":"Concatenating two edits XMLs and leaving duplicate or misplaced fragments; script-generated XML with wrong nesting; diff/patch repairs that reindented content into invalid positions.","solutions":["Restructure so every child of <EDITS> after <EDITS_VERSION> is exactly <RECORD>...</RECORD>.","Re-emit the document from the binary edits with oev instead of repairing nesting by hand.","Validate against a known-good dump: diff the element sequence (xmllint --shell or a SAX trace) to find the first divergent tag."],"exampleFix":"<!-- before -->\n<EDITS><EDITS_VERSION>-64</EDITS_VERSION>\n<DATA><TXID>1</TXID></DATA>\n<RECORD>...</RECORD></EDITS>\n\n<!-- after -->\n<EDITS><EDITS_VERSION>-64</EDITS_VERSION>\n<RECORD>...</RECORD></EDITS>","handlingStrategy":"try-catch","validationCode":"// Structural walk: after EDITS_VERSION, every start element must be RECORD\ntry (XMLStreamReader r = XMLInputFactory.newFactory()\n        .createXMLStreamReader(new FileInputStream(file))) {\n  r.next(); r.nextTag();                 // EDITS\n  r.nextTag();                           // EDITS_VERSION\n  while (r.hasNext()) {\n    int ev = r.next();\n    if (ev == XMLStreamConstants.START_ELEMENT\n        && !\"RECORD\".equals(r.getLocalName())) {\n      throw new IOException(\"Expected <RECORD>, found <\" + r.getLocalName() + \">\");\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  if (e.getMessage().contains(\"<RECORD>\")) {\n    System.err.println(\"Edits XML has a stray element between records: \"\n        + e.getMessage() + \" - regenerate from binary edits\");\n  }\n}","preventionTips":["Merge edits XML at the record level with a proper XML writer, never by string concatenation.","Diff the tag sequence against a known-good dump when a merged file starts failing."],"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"}