{"record":{"id":"bbcb15dd8486d6a5","repo":"apache/hadoop","slug":"dirdiffentry-contained-no-count-entry","errorCode":null,"errorMessage":"<dirDiffEntry> contained no <count> entry.","messagePattern":"<dirDiffEntry> contained no <count> entry\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java","lineNumber":1439,"sourceCode":"      recordSectionLength(SectionName.SNAPSHOT_DIFF.name());\n    }\n\n    private void processDirDiffEntry() throws IOException {\n      LOG.debug(\"Processing dirDiffEntry\");\n      DiffEntry.Builder headerBld = DiffEntry.newBuilder();\n      headerBld.setType(DiffEntry.Type.DIRECTORYDIFF);\n      Node dirDiffHeader = new Node();\n      loadNodeChildren(dirDiffHeader, \"dirDiffEntry fields\", \"dirDiff\");\n      Long inodeId = dirDiffHeader.removeChildLong(\n          SNAPSHOT_DIFF_SECTION_INODE_ID);\n      if (inodeId == null) {\n        throw new IOException(\"<dirDiffEntry> contained no <inodeId> entry.\");\n      }\n      headerBld.setInodeId(inodeId);\n      Integer expectedDiffs = dirDiffHeader.removeChildInt(\n          SNAPSHOT_DIFF_SECTION_COUNT);\n      if (expectedDiffs == null) {\n        throw new IOException(\"<dirDiffEntry> contained no <count> entry.\");\n      }\n      headerBld.setNumOfDiff(expectedDiffs);\n      dirDiffHeader.verifyNoRemainingKeys(\"dirDiffEntry\");\n      headerBld.build().writeDelimitedTo(out);\n      for (int actualDiffs = 0; actualDiffs < expectedDiffs; actualDiffs++) {\n        try {\n          expectTag(SNAPSHOT_DIFF_SECTION_DIR_DIFF, false);\n        } catch (IOException e) {\n          throw new IOException(\"Only read \" + (actualDiffs + 1) +\n              \" diffs out of \" + expectedDiffs, e);\n        }\n        Node dirDiff = new Node();\n        loadNodeChildren(dirDiff, \"dirDiff fields\");\n        FsImageProto.SnapshotDiffSection.DirectoryDiff.Builder bld =\n            FsImageProto.SnapshotDiffSection.DirectoryDiff.newBuilder();\n        Integer snapshotId = dirDiff.removeChildInt(\n            SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID);\n        if (snapshotId != null) {","sourceCodeStart":1421,"sourceCodeEnd":1457,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L1421-L1457","documentation":"A <dirDiffEntry> header is missing its <count> child, which tells the reconstructor how many <dirDiff> elements follow. Without it the protobuf DiffEntry.numOfDiff cannot be set, so the tool aborts before reading any diffs for this inode.","triggerScenarios":"A <dirDiffEntry> whose <count> was omitted or renamed during editing, or whose header was restructured so <count> ended up after the first <dirDiff> (headers stop at that terminator).","commonSituations":"Entries hand-written or script-generated without the count; counts removed because they 'looked redundant'; XML from a writer version that used a different field name.","solutions":["Add <count>N</count> to the entry header, where N is the number of <dirDiff> children that follow","Count the <dirDiff> elements in the entry and make <count> match exactly","Confirm <count> appears before the first <dirDiff>","Regenerate the XML with a matching-version oiv"],"exampleFix":"<!-- before: no count -->\n<dirDiffEntry><inodeId>16386</inodeId>\n  <dirDiff>...</dirDiff><dirDiff>...</dirDiff>\n</dirDiffEntry>\n<!-- after -->\n<dirDiffEntry><inodeId>16386</inodeId><count>2</count>\n  <dirDiff>...</dirDiff><dirDiff>...</dirDiff>\n</dirDiffEntry>","handlingStrategy":"validation","validationCode":"# python: every dirDiffEntry needs <count> equal to its <dirDiff> children\nimport xml.etree.ElementTree as ET\n\ndef dir_counts_ok(path):\n    for ev, el in ET.iterparse(path, events=('end',)):\n        if el.tag == 'dirDiffEntry':\n            c = el.find('count')\n            if c is None or int(c.text) != len(el.findall('dirDiff')):\n                return False\n    return True","typeGuard":null,"tryCatchPattern":"// catch non-zero oiv exit; message names the entry missing <count>\n// fix the header, remove the partial output file, re-run","preventionTips":["Treat <count> as derived data: scripts must recount, never trust stale values","Keep <count> adjacent to <inodeId> in the header","Validate count vs children for every entry pre-flight","Regenerate the dump instead of hand-maintaining counts"],"tags":["hdfs","oiv","fsimage","reversexml","snapshot-diff","missing-field"],"backgroundTag":"missing-required-xml-element","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}