{"record":{"id":"83ce5ec72e075e6a","repo":"apache/hadoop","slug":"expected-to-find-childrensize-in-dirdiff-secti","errorCode":null,"errorMessage":"Expected to find <childrenSize> in <dirDiff> section.","messagePattern":"Expected to find <childrenSize> in <dirDiff> section\\.","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":1463,"sourceCode":"        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) {\n          bld.setSnapshotId(snapshotId);\n        }\n        Integer childrenSize = dirDiff.removeChildInt(\n            SNAPSHOT_DIFF_SECTION_CHILDREN_SIZE);\n        if (childrenSize == null) {\n          throw new IOException(\"Expected to find <childrenSize> in \" +\n              \"<dirDiff> section.\");\n        }\n        bld.setIsSnapshotRoot(dirDiff.removeChildBool(\n            SNAPSHOT_DIFF_SECTION_IS_SNAPSHOT_ROOT));\n        bld.setChildrenSize(childrenSize);\n        String name = dirDiff.removeChildStr(SECTION_NAME);\n        if (name != null) {\n          bld.setName(ByteString.copyFrom(name, StandardCharsets.UTF_8));\n        }\n        Node snapshotCopy = dirDiff.removeChild(\n            SNAPSHOT_DIFF_SECTION_SNAPSHOT_COPY);\n        if (snapshotCopy != null) {\n          bld.setSnapshotCopy(createINodeDirectoryBuilder(snapshotCopy));\n        }\n        Integer expectedCreatedListSize = dirDiff.removeChildInt(\n            SNAPSHOT_DIFF_SECTION_CREATED_LIST_SIZE);\n        if (expectedCreatedListSize == null) {\n          throw new IOException(\"Expected to find <createdListSize> in \" +","sourceCodeStart":1445,"sourceCodeEnd":1481,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L1445-L1481","documentation":"A <dirDiff> element is missing <childrenSize>, which the protobuf DirectoryDiff requires (it is a mandatory field, unlike the optional <snapshotId> and <name> read just before it). removeChildInt on the loaded dirDiff node returned null, so reconstruction aborts for this diff.","triggerScenarios":"A <dirDiff> hand-authored or trimmed without <childrenSize>, or the field renamed/misspelled (exact tag 'childrenSize' required); also fields accidentally nested inside <snapshotCopy> during restructuring.","commonSituations":"Hand-written diffs copied from a template that omitted the field; scripts emitting only the 'interesting' fields; XML from an older writer that predates the field.","solutions":["Add <childrenSize>N</childrenSize> to the affected <dirDiff> (the directory's children count in that snapshot; 0 is valid)","Check spelling, case, and nesting - it must be a direct child of <dirDiff>","Regenerate the XML from the original fsimage with a same-version oiv to recover the true values","Pre-scan for <dirDiff> elements lacking required children before running ReverseXML"],"exampleFix":"<!-- before -->\n<dirDiff><snapshotId>3</snapshotId><name>snap1</name></dirDiff>\n<!-- after -->\n<dirDiff><snapshotId>3</snapshotId><childrenSize>0</childrenSize><name>snap1</name></dirDiff>","handlingStrategy":"validation","validationCode":"# python: every <dirDiff> needs <childrenSize>\nimport xml.etree.ElementTree as ET\n\ndef dirdiffs_have_childrensize(path):\n    for ev, el in ET.iterparse(path, events=('end',)):\n        if el.tag == 'dirDiff' and el.find('childrenSize') is None:\n            return False\n    return True","typeGuard":null,"tryCatchPattern":"// oiv exit != 0 with 'Expected to find <childrenSize>' -> patch the named\n// <dirDiff>, delete partial output, retry","preventionTips":["childrenSize is mandatory even when 0 - templates must include it","Keep required fields direct children of <dirDiff>","Pre-scan for required fields on every dirDiff","Regenerate from the original image when values are unknown"],"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-23T01:17:44.959Z"}