{"record":{"id":"902b40ad9c3b56e1","repo":"apache/hadoop","slug":"expected-opcode","errorCode":null,"errorMessage":"expected </OPCODE>","messagePattern":"expected </OPCODE>","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":210,"sourceCode":"      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;\n        FSEditLogOp op = opCache.get(opCode);\n        opCode = null;\n        try {\n          op.decodeXml(stanza);\n          stanza = null;","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L192-L228","documentation":"Thrown from endElement() in EXPECT_OPCODE state: a <RECORD> was opened but the next element-close event was not </OPCODE>. Every <RECORD> must begin with exactly <OPCODE>OP_XXX</OPCODE> (its text is resolved via FSEditLogOpCodes.valueOf); a record that closes before a complete OPCODE element is rejected.","triggerScenarios":"An empty or self-closed record element: <RECORD/> or <RECORD></RECORD> — the </RECORD> close fires while the loader still waits for <OPCODE>. Also any record whose first child closes with a name other than OPCODE.","commonSituations":"Hand-deleting record bodies but leaving empty <RECORD> shells; line-based filtering tools that drop the opcode line but keep the record tags; template-generated edits files with unfilled records.","solutions":["Delete empty <RECORD/> or <RECORD></RECORD> blocks entirely — records are optional, but when present they must be complete.","Ensure every record reads <RECORD><OPCODE>OP_...</OPCODE><DATA>...</DATA></RECORD>.","Regenerate the file with hdfs oev rather than filtering the XML by hand."],"exampleFix":"// before\n<RECORD>\n  <OPCODE>OP_ADD</OPCODE>\n</RECORD>\n<RECORD/>\n\n// after\n<RECORD>\n  <OPCODE>OP_ADD</OPCODE>\n  <DATA>...</DATA>\n</RECORD>","handlingStrategy":"try-catch","validationCode":"private static boolean recordsAreComplete(String xml) {\n  // every RECORD must contain an OPCODE element\n  for (String rec : xml.split(\"(?s)(?=<RECORD>)\")) {\n    if (rec.startsWith(\"<RECORD\") && !rec.contains(\"<OPCODE>\")) return false;\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  // a <RECORD> lacked <OPCODE>...</OPCODE>; drop or complete empty records\n  LOG.error(\"Incomplete record in edits XML: {}\", e.getMessage());\n}","preventionTips":["Delete whole RECORD blocks when filtering, never just their children.","Validate that each <RECORD> contains both OPCODE and DATA before conversion.","Prefer regenerating from the binary edit log over hand-filtering XML."],"tags":["hdfs","offline-edits-viewer","oev","edit-log","xml","record-validation"],"backgroundTag":"malformed-xml-input","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}