{"record":{"id":"057852261f961d3c","repo":"apache/hadoop","slug":"value-of-layoutversion-is-null","errorCode":null,"errorMessage":"Value of <layoutVersion> is null","messagePattern":"Value of <layoutVersion> is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ECPolicyLoader.java","lineNumber":148,"sourceCode":"  /**\n   * Load layoutVersion from root element in the XML configuration file.\n   * @param root root element\n   * @return layout version\n   */\n  private int loadLayoutVersion(Element root) {\n    int layoutVersion;\n    Text text = (Text) root.getElementsByTagName(\"layoutversion\")\n        .item(0).getFirstChild();\n    if (text != null) {\n      String value = text.getData().trim();\n      try {\n        layoutVersion = Integer.parseInt(value);\n      } catch (NumberFormatException e) {\n        throw new IllegalArgumentException(\"Bad layoutVersion value \"\n            + value + \" is found. It should be an integer\");\n      }\n    } else {\n      throw new IllegalArgumentException(\"Value of <layoutVersion> is null\");\n    }\n\n    return layoutVersion;\n  }\n\n  /**\n   * Load schemas from root element in the XML configuration file.\n   * @param root root element\n   * @return EC schema map\n   */\n  private Map<String, ECSchema> loadSchemas(Element root) {\n    NodeList elements = root.getElementsByTagName(\"schemas\")\n        .item(0).getChildNodes();\n    Map<String, ECSchema> schemas = new HashMap<String, ECSchema>();\n    for (int i = 0; i < elements.getLength(); i++) {\n      Node node = elements.item(i);\n      if (node instanceof Element) {\n        Element element = (Element) node;","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ECPolicyLoader.java#L130-L166","documentation":"ECPolicyLoader.loadLayoutVersion() found the <layoutversion> element but its first child text node is null, meaning the element is empty (<layoutversion/> or <layoutversion></layoutversion>). Thrown as IllegalArgumentException before any parsing is attempted. An element containing only whitespace is not empty — whitespace text is trimmed and would fail as a bad integer instead.","triggerScenarios":"`hdfs ec -loadPolicy` on a file with an empty <layoutversion/> element, typically left behind when a template value was deleted instead of replaced.","commonSituations":"Editing user_ec_policies.xml.template and clearing the placeholder text rather than typing 1 into it.","solutions":["Put the value 1 inside the element: <layoutversion>1</layoutversion>","If versioning is not intentional, restore the template file from the Hadoop distribution and reapply edits"],"exampleFix":"<!-- before -->\n<layoutversion/>\n\n<!-- after -->\n<layoutversion>1</layoutversion>","handlingStrategy":"validation","validationCode":"Node n = doc.getElementsByTagName(\"layoutversion\").item(0).getFirstChild();\nif (n == null || n.getNodeValue().trim().isEmpty()) {\n  throw new IllegalArgumentException(\"<layoutversion> must contain the value 1\");\n}","typeGuard":null,"tryCatchPattern":"try { new ECPolicyLoader().loadPolicy(path); }\ncatch (IllegalArgumentException e) {\n  LOG.error(\"EC policy file {} rejected: {}\", path, e.getMessage());\n}","preventionTips":["After editing, grep for empty elements: grep -nE '<(layoutversion|k|m|codec|schema|cellsize)/>' file.xml","Replace template placeholders rather than deleting them"],"tags":["hdfs","erasure-coding","ec-policy","xml","configuration"],"backgroundTag":"xml-config-missing-element","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}