{"record":{"id":"ad22b0b6ec99be19","repo":"apache/hadoop","slug":"expected-data","errorCode":null,"errorMessage":"expected <DATA/>","messagePattern":"expected <DATA/>","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":216,"sourceCode":"      }\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;\n        } finally {\n          if (stanza != null) {\n            System.err.println(\"fromXml error decoding opcode \" + opCode +\n                \"\\n\" + stanza.toString());\n            stanza = null;\n          }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineEditsViewer/OfflineEditsXmlLoader.java#L198-L234","documentation":"Thrown from endElement() in EXPECT_DATA state: the <OPCODE> element closed (its text was consumed as the op code) but the next event was a close tag instead of the required <DATA> opening. The loader mandates a <DATA> stanza immediately after OPCODE in every record; a record ending right after </OPCODE> is rejected.","triggerScenarios":"A record of the form <RECORD><OPCODE>OP_ADD</OPCODE></RECORD> — the </RECORD> close arrives while the parser waits for <DATA> to open. Any close tag between </OPCODE> and <DATA> has the same effect.","commonSituations":"Hand-trimming 'uninteresting' DATA blocks to shrink files; scripts that strip DATA elements; edits XML produced by third-party generators that omit DATA.","solutions":["Give every record its <DATA>...</DATA> block, copied verbatim from the original oev output.","Delete whole <RECORD> blocks instead of just their DATA parts when filtering.","Regenerate the XML from the binary edit log with hdfs oev."],"exampleFix":"// before\n<RECORD>\n  <OPCODE>OP_MKDIR</OPCODE>\n</RECORD>\n\n// after\n<RECORD>\n  <OPCODE>OP_MKDIR</OPCODE>\n  <DATA><TXID>1</TXID><PATH>/tmp</PATH><TIMESTAMP>...</TIMESTAMP><OWNER>hdfs</OWNER><GROUP>hdfs</GROUP><PERMISSION_STRING>755</PERMISSION_STRING></DATA>\n</RECORD>","handlingStrategy":"try-catch","validationCode":"private static boolean recordHasData(String xml) {\n  for (String rec : xml.split(\"(?s)(?=<RECORD>)\")) {\n    if (rec.startsWith(\"<RECORD\") && rec.contains(\"<OPCODE>\") && !rec.contains(\"<DATA\")) {\n      return false;\n    }\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  loader.loadEdits();\n} catch (InvalidXmlException e) {\n  // record ended after </OPCODE> with no <DATA>; restore the DATA stanza\n  LOG.error(\"Record missing DATA element: {}\", e.getMessage());\n}","preventionTips":["Treat OPCODE and DATA as an inseparable pair inside every RECORD.","Do not strip DATA blocks to slim files — delete whole records instead.","Test generators against a tiny known-good file round-tripped through oev."],"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"}