{"record":{"id":"197f19549feb7bba","repo":"apache/hadoop","slug":"bad-ec-policy-configuration-file-no-policies-el","errorCode":null,"errorMessage":"Bad EC policy configuration file: no <policies> element","messagePattern":"Bad EC policy configuration file: no <policies> element","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":111,"sourceCode":"    dbf.setIgnoringComments(true);\n    DocumentBuilder builder = dbf.newDocumentBuilder();\n    Document doc = builder.parse(policyFile);\n    Element root = doc.getDocumentElement();\n\n    if (!\"configuration\".equals(root.getTagName())) {\n      throw new RuntimeException(\"Bad EC policy configuration file: \"\n          + \"top-level element not <configuration>\");\n    }\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","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ECPolicyLoader.java#L93-L129","documentation":"Inside <configuration>, ECPolicyLoader validates three sections in order: <layoutversion>, then <schemas>, then <policies>. If layoutversion matches and schemas exist but no <policies> element is present - the element that actually carries the list of policy entries - loading aborts with 'Bad EC policy configuration file: no <policies> element'. The container validated fine but the payload is missing.","triggerScenarios":"`hdfs ec -addPolicies` with a file that has <layoutversion> and <schemas> but no <policies> element: the block was deleted, commented out, or misspelled (e.g. <policy> or <Policies>).","commonSituations":"Typos in element names; blocks commented out during debugging; templates trimmed too aggressively.","solutions":["Add a <policies> element containing one <policy> entry per EC policy you want to add","Check spelling and case - the loader matches the literal lowercase tag 'policies'","Model the file on the shipped user-ec-policies.xml example"],"exampleFix":"<!-- before: layoutversion + schemas only -->\n<configuration>\n  <layoutversion>1</layoutversion>\n  <schemas>...</schemas>\n</configuration>\n\n<!-- after -->\n<configuration>\n  <layoutversion>1</layoutversion>\n  <schemas>...</schemas>\n  <policies>\n    <policy><name>MY-POLICY</name><!-- schemaId, cellsize... --></policy>\n  </policies>\n</configuration>","handlingStrategy":"validation","validationCode":"Element root = doc.getDocumentElement();\nboolean hasPolicies = root.getElementsByTagName(\"policies\").getLength() > 0;\nif (!hasPolicies) { /* reject before loadPolicy */ }","typeGuard":null,"tryCatchPattern":"try {\n  new ECPolicyLoader().loadPolicy(path);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"no <policies> element\")) {\n    // add a <policies> block with <policy> entries and retry\n  } else { throw e; }\n}","preventionTips":["Check required sections (layoutversion, schemas, policies) as a deployment lint step","Beware typos and case: the loader matches literal lowercase tags"],"tags":["hdfs","erasure-coding","ec-policy","xml","schema-validation","missing-element"],"backgroundTag":"config-xml-schema-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}