apache/hadoop · error · IllegalArgumentException

Bad EC policy cellsize value {value} is found. It should be

Error message

Bad EC policy cellsize value {value} is found. It should be an integer

What it means

ECPolicyLoader.loadPolicy() Integer.parseInt() on the text of a policy's <cellsize> element failed, so the cell size is not a plain integer. Thrown as IllegalArgumentException with the offending value. The cell size is the striping cell size in bytes (typical value 1MB = 1048576); memory-style units like '1MB' or '1m' are not accepted.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/util/ECPolicyLoader.java:306

    for (int i = 0; i < fields.getLength(); i++) {
      Node fieldNode = fields.item(i);
      if (fieldNode instanceof Element) {
        Element field = (Element) fieldNode;
        String tagName = field.getTagName();

        // Get the nonnull text value.
        Text text = (Text) field.getFirstChild();
        if (text != null) {
          if (!text.isElementContentWhitespace()) {
            String value = text.getData().trim();
            if ("schema".equals(tagName)) {
              schema = schemas.get(value);
            } else if ("cellsize".equals(tagName)) {
              try {
                cellSize = Integer.parseInt(value);
              } catch (NumberFormatException e) {
                throw new IllegalArgumentException("Bad EC policy cellsize"
                    + " value " + value + " is found. It should be an integer");
              }
            } else {
              LOG.warn("Invalid tagName: " + tagName);
            }
          }
        } else {
          throw new IllegalArgumentException("Value of <" + tagName
              + "> is null");
        }
      }
    }

    if (schema != null && cellSize > 0) {
      return new ErasureCodingPolicy(schema, cellSize);
    } else {
      throw new RuntimeException("Bad policy is found in"
          + " EC policy configuration file");

View on GitHub (pinned to 2add963021)

Solutions

  1. Use a plain integer byte count: <cellsize>1048576</cellsize> for 1MB
  2. Remove units, commas, and decimal points from the value
  3. Keep the value positive; 0 or negative passes the parse but fails the final policy validation

Example fix

<!-- before -->
<cellsize>1MB</cellsize>

<!-- after -->
<cellsize>1048576</cellsize>
Defensive patterns

Strategy: validation

Validate before calling

String cs = textOf(policyElement, "cellsize").trim();
try {
  if (Integer.parseInt(cs) <= 0) throw new IllegalArgumentException("cellsize must be > 0");
} catch (NumberFormatException e) {
  throw new IllegalArgumentException("cellsize '" + cs + "' must be a plain integer byte count (e.g. 1048576)");
}

Try / catch

try { new ECPolicyLoader().loadPolicy(path); }
catch (IllegalArgumentException e) {
  LOG.error("EC policy file {} rejected: {}", path, e.getMessage());
}

Prevention

When it happens

Trigger: `hdfs ec -loadPolicy` where a policy contains <cellsize>1MB</cellsize>, <cellsize>1024.0</cellsize>, or any non-integer text. Note the value must also be > 0 or the later 'Bad policy is found' check fails.

Common situations: Writing human-readable sizes (64k, 1MB) as with other Hadoop configs that accept size suffixes; the EC policy XML accepts raw bytes only.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/39763148672fa41a. Report an issue: GitHub.