{"record":{"id":"6e47d3c6d76c9f0a","repo":"apache/hadoop","slug":"more-than-one-value-found-for","errorCode":null,"errorMessage":"More than one value found for {}","messagePattern":"More than one value found for (.+?)","errorType":"exception","errorClass":"InvalidXmlException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/XMLUtils.java","lineNumber":332,"sourceCode":"        throw new InvalidXmlException(\"no entry found for \" + name);\n      }\n      return ret;\n    }\n\n    /** \n     * Pull a string entry from a stanza, or null.\n     *\n     * @param name        entry to look for\n     * \n     * @return            the entry, or null if it was not found.\n     */\n    public String getValueOrNull(String name) throws InvalidXmlException {\n      if (!subtrees.containsKey(name)) {\n        return null;\n      }\n      LinkedList <Stanza> l = subtrees.get(name);\n      if (l.size() != 1) {\n        throw new InvalidXmlException(\"More than one value found for \" + name);\n      }\n      return l.get(0).getValue();\n    }\n    \n    /** \n     * Add an entry to a stanza.\n     *\n     * @param name        name of the entry to add\n     * @param child       the entry to add\n     */\n    public void addChild(String name, Stanza child) {\n      LinkedList<Stanza> l;\n      if (subtrees.containsKey(name)) {\n        l = subtrees.get(name);\n      } else {\n        l = new LinkedList<Stanza>();\n        subtrees.put(name, l);\n      }","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/XMLUtils.java#L314-L350","documentation":"Stanza.getValueOrNull accepts an entry only when its list has exactly one stanza: it checks subtrees.containsKey(name), fetches the LinkedList, and throws InvalidXmlException(\"More than one value found for \" + name) when l.size() != 1. In well-formed fsimage XML each scalar field appears once per parent, so a size other than 1 means malformed input (0 can also land here only if the key was added with an empty list; the common case is 2+).","triggerScenarios":"The XML contains the same element twice inside one parent (e.g. two <NAME> children under one <INODE>), so the stanza's list for that name has size 2; any getValue/getValueOrNull call on it throws.","commonSituations":"Merging or hand-editing OIV XML that duplicated a field; buggy XML generators emitting repeated elements; processing concatenated or diff-merged dumps.","solutions":["Remove the duplicate element so exactly one remains","If multiple values are legitimate for your data model, read them with getChildren(name) instead of getValue(name)","Validate uniqueness (count occurrences per parent element) before parsing"],"exampleFix":"<!-- before: duplicate element inside one parent -->\n<INODE><NAME>a</NAME><NAME>b</NAME></INODE>\n\n<!-- after -->\n<INODE><NAME>a</NAME></INODE>","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  String v = stanza.getValue(name);\n} catch (InvalidXmlException e) {\n  // size != 1: duplicated element in the XML stanza\n}","preventionTips":["Ensure generators emit scalar fields exactly once per parent","Avoid merging XML fragments that duplicate fields","Use getChildren(name) when multiple entries are valid for your data"],"tags":["xml","fsimage","offline-image-viewer","hdfs","parsing"],"backgroundTag":"duplicate-xml-element","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}