{"record":{"id":"0e8152c794439a9f","repo":"apache/hadoop","slug":"bad-ec-policy-configuration-file-no-schemas-ele","errorCode":null,"errorMessage":"Bad EC policy configuration file: no <schemas> element","messagePattern":"Bad EC policy configuration file: no <schemas> 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":115,"sourceCode":"\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\n  /**\n   * Load layoutVersion from root element in the XML configuration file.\n   * @param root root element\n   * @return layout version","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ECPolicyLoader.java#L97-L133","documentation":"The second structural check: <schemas> must declare the EC schemas (codec, data/parity units) that <policies> reference by name. If <layoutversion> is present and correct but <schemas> is absent, policies would reference undefined schemas, so loading aborts with 'Bad EC policy configuration file: no <schemas> element'.","triggerScenarios":"`hdfs ec -addPolicies` with a file that skips <schemas> and inlines codec parameters directly inside each <policy> - the format requires schemas to be declared separately and referenced by name.","commonSituations":"Users inlining schema parameters into policies; files written against an imagined simpler format; the schemas block deleted because it looked redundant.","solutions":["Add a <schemas> section declaring each schema once (id, codec, data units, parity units)","Reference schemas from policies by name via <schemaId> and make sure every reference has a matching declaration","Model the file on the shipped user-ec-policies.xml example"],"exampleFix":"<!-- before: policies only, schemas undefined -->\n<configuration>\n  <layoutversion>1</layoutversion>\n  <policies><policy><name>P</name><schemaId>MY-SCHEMA</schemaId></policy></policies>\n</configuration>\n\n<!-- after -->\n<configuration>\n  <layoutversion>1</layoutversion>\n  <schemas><schema><id>MY-SCHEMA</id><!-- codec, units... --></schema></schemas>\n  <policies><policy><name>P</name><schemaId>MY-SCHEMA</schemaId></policy></policies>\n</configuration>","handlingStrategy":"validation","validationCode":"Element root = doc.getDocumentElement();\nboolean hasSchemas = root.getElementsByTagName(\"schemas\").getLength() > 0;\nif (!hasSchemas) { /* 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 <schemas> element\")) {\n    // declare schemas once in <schemas> and reference them by id from policies\n  } else { throw e; }\n}","preventionTips":["Declare schemas centrally and reference by name; never inline codec parameters in policies","Cross-check every <schemaId> referenced in policies has a matching <schema> entry"],"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"}