{"record":{"id":"2b5d96dbda340e3c","repo":"apache/hadoop","slug":"node-key-contains-children-of-its-own","errorCode":null,"errorMessage":"Node {key} contains children of its own.","messagePattern":"Node (.+?) contains children of its own\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java","lineNumber":287,"sourceCode":"      }\n      LinkedList<Node> cur = children.get(key);\n      if (cur == null) {\n        return null;\n      }\n      Node node = cur.remove();\n      if ((node == null) || cur.isEmpty()) {\n        children.remove(key);\n      }\n      return node;\n    }\n\n    String removeChildStr(String key) {\n      Node child = removeChild(key);\n      if (child == null) {\n        return null;\n      }\n      if ((child.children != null) && (!child.children.isEmpty())) {\n        throw new RuntimeException(\"Node \" + key + \" contains children \" +\n            \"of its own.\");\n      }\n      return child.getVal();\n    }\n\n    Integer removeChildInt(String key) throws IOException {\n      String str = removeChildStr(key);\n      if (str == null) {\n        return null;\n      }\n      return Integer.valueOf(str);\n    }\n\n    Long removeChildLong(String key) throws IOException {\n      String str = removeChildStr(key);\n      if (str == null) {\n        return null;\n      }","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L269-L305","documentation":"removeChildStr(key) removes a child from the current Node and returns its text value, but first asserts the node has no children of its own (OfflineImageReconstructor.java:287). This RuntimeException (not IOException) fires when the XML maps a scalar field onto an element that contains nested elements - the value of <key> is structured where the fsimage schema demands a plain number or string.","triggerScenarios":"Any SectionProcessor reading a scalar field such as <replication>, <nsQuota>, <numBytes>, or <namespaceId> whose element wraps child elements instead of text - e.g. <replication><desired>3</desired></replication> - typically from hand edits or transforms that 'type-annotate' values.","commonSituations":"Wrapping values to attach metadata (<id><long>16386</long></id>); XML produced by exporters that model every value as a tree.","solutions":["Flatten the element so its content is a single text value","If the nested structure carries real fields, re-express them as correctly named sibling elements the processor understands","Regenerate the XML from the original fsimage and redo the edit structurally"],"exampleFix":"<!-- before: scalar field wrapped in child elements -->\n<replication><desired>3</desired></replication>\n\n<!-- after -->\n<replication>3</replication>","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Guard: only treat an element as a scalar value when it is a leaf\nstatic boolean isLeafElement(org.w3c.dom.Node n) {\n  NodeList children = n.getChildNodes();\n  for (int i = 0; i < children.getLength(); i++) {\n    if (children.item(i).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {\n      return false;\n    }\n  }\n  return true;\n}\n\n// use before reading any scalar field in pre-flight validation:\nNodeList scalars = xpath.evaluate(\"//replication\", doc, XPathConstants.NODESET);\nfor (int i = 0; i < scalars.getLength(); i++) {\n  if (!isLeafElement(scalars.item(i))) {\n    throw new IllegalArgumentException(\n        scalars.item(i).getNodeName() + \" must contain text, not child elements\");\n  }\n}","tryCatchPattern":null,"preventionTips":["Keep scalar fields as plain text - never wrap values in child elements","When a field needs structure, express it as the named sibling elements oiv emits","Run a leaf-check over scalar fields as a pre-flight step after transforms"],"tags":["hdfs","reversexml","xml-nesting","fsimage"],"backgroundTag":"xml-nesting-violation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}