{"record":{"id":"100dc35e90259fb6","repo":"apache/hadoop","slug":"the-parse-failed-because-of-bad-layoutversion-valu","errorCode":null,"errorMessage":"The parse failed because of bad layoutversion value","messagePattern":"The parse failed because of bad layoutversion value","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ECPolicyLoader.java","lineNumber":119,"sourceCode":"    }\n\n    List<ErasureCodingPolicy> policies;\n    if (root.getElementsByTagName(\"layoutversion\").getLength() > 0) {\n      if (loadLayoutVersion(root) == LAYOUT_VERSION) {\n        if (root.getElementsByTagName(\"schemas\").getLength() > 0) {\n          Map<String, ECSchema> schemas = loadSchemas(root);\n          if (root.getElementsByTagName(\"policies\").getLength() > 0) {\n            policies = loadPolicies(root, schemas);\n          } else {\n            throw new RuntimeException(\"Bad EC policy configuration file: \"\n                + \"no <policies> element\");\n          }\n        } else {\n          throw new RuntimeException(\"Bad EC policy configuration file: \"\n              + \"no <schemas> element\");\n        }\n      } else {\n        throw new RuntimeException(\"The parse failed because of \"\n            + \"bad layoutversion value\");\n      }\n    } else {\n      throw new RuntimeException(\"Bad EC policy configuration file: \"\n          + \"no <layoutVersion> element\");\n    }\n\n    return policies;\n  }\n\n  /**\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\")","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ECPolicyLoader.java#L101-L137","documentation":"The first content check inside <configuration>: the <layoutversion> element must parse as an integer and equal 1 (LAYOUT_VERSION in ECPolicyLoader), the only policy-file format generation this Hadoop version understands. A value that parses but differs (0, 2, -1) produces 'The parse failed because of bad layoutversion value'. The check stops files from a different format generation from being silently misread.","triggerScenarios":"`hdfs ec -addPolicies -policyFile` with <layoutversion> set to anything other than 1 - usually a file taken from a different Hadoop release whose format generation differs, or a hand-written file that guessed the value.","commonSituations":"Policy files copied between Hadoop versions; files authored from outdated documentation; a leftover 0 from early custom setups.","solutions":["Set <layoutversion>1</layoutversion> - the only supported value in this codebase","Regenerate the file from the user-ec-policies.xml template shipped with your exact Hadoop version","If the file came from another cluster version, re-express its schemas and policies in this version's template rather than just editing the number"],"exampleFix":"<!-- before -->\n<layoutversion>0</layoutversion>\n\n<!-- after -->\n<layoutversion>1</layoutversion>","handlingStrategy":"validation","validationCode":"NodeList lv = doc.getDocumentElement().getElementsByTagName(\"layoutversion\");\nif (lv.getLength() == 0\n    || Integer.parseInt(lv.item(0).getFirstChild().getNodeValue().trim()) != 1) {\n  // only layout version 1 is supported by this loader\n}","typeGuard":null,"tryCatchPattern":"try {\n  new ECPolicyLoader().loadPolicy(path);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"bad layoutversion value\")) {\n    // set <layoutversion>1</layoutversion> or regenerate the file from this version's template\n  } else { throw e; }\n}","preventionTips":["Regenerate policy files from the template of the target Hadoop version instead of copying across releases","Treat layoutversion mismatches as format-generation changes, not editable constants"],"tags":["hdfs","erasure-coding","ec-policy","xml","layout-version","version-mismatch"],"backgroundTag":"layout-version-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}