{"record":{"id":"c90dbf316b812bd5","repo":"apache/hadoop","slug":"expected-an-opcode-tag","errorCode":null,"errorMessage":"expected an <OPCODE> tag","messagePattern":"expected an <OPCODE> 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":159,"sourceCode":"      }\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();\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>\");","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L141-L177","documentation":"Inside a <RECORD>, the state machine enters EXPECT_OPCODE and the first child element must be <OPCODE> (the numeric edit opcode). Any other tag first throws InvalidXmlException('expected an <OPCODE> tag'). Records are rigidly ordered: OPCODE then DATA.","triggerScenarios":"A <RECORD> whose first child is <DATA> (order swapped or OPCODE deleted), or an extra wrapper element inserted before the opcode during manual editing or transform.","commonSituations":"Hand-crafted fixtures with reversed children; XML transformers reordering children alphabetically (DATA before OPCODE); merging records and losing the opcode element.","solutions":["Put <OPCODE>value</OPCODE> immediately inside <RECORD>, before <DATA>.","Disable child reordering in any XSLT/serializer used to produce the file.","Regenerate from the binary edits via oev to guarantee opcode/data ordering."],"exampleFix":"<!-- before -->\n<RECORD><DATA><TXID>1</TXID></DATA><OPCODE>9</OPCODE></RECORD>\n\n<!-- after -->\n<RECORD><OPCODE>9</OPCODE><DATA><TXID>1</TXID></DATA></RECORD>","handlingStrategy":"validation","validationCode":"// Inside each RECORD, first child must be OPCODE\ntry (XMLStreamReader r = XMLInputFactory.newFactory()\n        .createXMLStreamReader(new FileInputStream(file))) {\n  while (r.hasNext()) {\n    int ev = r.next();\n    if (ev == XMLStreamConstants.START_ELEMENT\n        && \"RECORD\".equals(r.getLocalName())) {\n      r.nextTag();\n      if (!\"OPCODE\".equals(r.getLocalName())) {\n        throw new IOException(\"<RECORD> must start with <OPCODE>, found <\"\n            + r.getLocalName() + \">\");\n      }\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  if (e.getMessage().contains(\"<OPCODE>\")) {\n    throw new IOException(\"Record children are order-sensitive: \"\n        + \"<OPCODE> must precede <DATA>. \" + e.getMessage(), e);\n  }\n  throw e;\n}","preventionTips":["Never reorder record children; the loader requires OPCODE before DATA.","Disable alphabetizing serializers when producing edits XML."],"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"}