{"record":{"id":"0982444757314f75","repo":"apache/hadoop","slug":"filediffentry-contained-no-count-entry","errorCode":null,"errorMessage":"<fileDiffEntry> contained no <count> entry.","messagePattern":"<fileDiffEntry> 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":1546,"sourceCode":"      expectTagEnd(SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY);\n    }\n\n    private void processFileDiffEntry() throws IOException {\n      LOG.debug(\"Processing fileDiffEntry\");\n      DiffEntry.Builder headerBld = DiffEntry.newBuilder();\n      headerBld.setType(DiffEntry.Type.FILEDIFF);\n      Node fileDiffHeader = new Node();\n      loadNodeChildren(fileDiffHeader, \"fileDiffEntry fields\", \"fileDiff\");\n      Long inodeId = fileDiffHeader.removeChildLong(\n          SNAPSHOT_DIFF_SECTION_INODE_ID);\n      if (inodeId == null) {\n        throw new IOException(\"<fileDiffEntry> contained no <inodeid> entry.\");\n      }\n      headerBld.setInodeId(inodeId);\n      Integer expectedDiffs = fileDiffHeader.removeChildInt(\n          SNAPSHOT_DIFF_SECTION_COUNT);\n      if (expectedDiffs == null) {\n        throw new IOException(\"<fileDiffEntry> contained no <count> entry.\");\n      }\n      headerBld.setNumOfDiff(expectedDiffs);\n      fileDiffHeader.verifyNoRemainingKeys(\"fileDiffEntry\");\n      headerBld.build().writeDelimitedTo(out);\n      for (int actualDiffs = 0; actualDiffs < expectedDiffs; actualDiffs++) {\n        try {\n          expectTag(SNAPSHOT_DIFF_SECTION_FILE_DIFF, false);\n        } catch (IOException e) {\n          throw new IOException(\"Only read \" + (actualDiffs + 1) +\n              \" diffs out of \" + expectedDiffs, e);\n        }\n        Node fileDiff = new Node();\n        loadNodeChildren(fileDiff, \"fileDiff fields\");\n        FsImageProto.SnapshotDiffSection.FileDiff.Builder bld =\n            FsImageProto.SnapshotDiffSection.FileDiff.newBuilder();\n        Integer snapshotId = fileDiff.removeChildInt(\n            SNAPSHOT_DIFF_SECTION_SNAPSHOT_ID);\n        if (snapshotId != null) {","sourceCodeStart":1528,"sourceCodeEnd":1564,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L1528-L1564","documentation":"A <fileDiffEntry> header is missing its <count> child, which declares how many <fileDiff> elements follow and becomes DiffEntry.numOfDiff. Without it the reconstructor cannot loop over the diffs and aborts the entry.","triggerScenarios":"A <fileDiffEntry> with <count> omitted, renamed, or positioned after the first <fileDiff> terminator; header fields damaged by line-based edits.","commonSituations":"Hand-edited or script-generated entries missing the count; counts dropped as 'redundant'; version-skewed XML writers.","solutions":["Add <count>N</count> to the entry header, N being the number of <fileDiff> children present","Verify <count> precedes the first <fileDiff>","Pre-validate every <fileDiffEntry> carries both <inodeId> and <count>","Regenerate the XML from the original image"],"exampleFix":"<!-- before -->\n<fileDiffEntry><inodeId>16390</inodeId>\n  <fileDiff>...</fileDiff>\n</fileDiffEntry>\n<!-- after -->\n<fileDiffEntry><inodeId>16390</inodeId><count>1</count>\n  <fileDiff>...</fileDiff>\n</fileDiffEntry>","handlingStrategy":"validation","validationCode":"# python: every fileDiffEntry needs <count> equal to its <fileDiff> children\nimport xml.etree.ElementTree as ET\n\ndef file_counts_ok(path):\n    for ev, el in ET.iterparse(path, events=('end',)):\n        if el.tag == 'fileDiffEntry':\n            c = el.find('count')\n            if c is None or int(c.text) != len(el.findall('fileDiff')):\n                return False\n    return True","typeGuard":null,"tryCatchPattern":"// catch '<fileDiffEntry> contained no <count>'; add/recount it,\n// delete partial output, re-run oiv","preventionTips":["Scripts must recount <count> after edits, never copy stale values","Keep header fields before the first <fileDiff>","Validate presence and consistency pre-flight","Regenerate the dump instead of hand-fixing many entries"],"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"}