apache/hadoop · error · IllegalArgumentException

Cannot parse string "{s}"

Error message

Cannot parse string "{s}"

What it means

BalancingPolicy.parse maps the '-policy' CLI value to a policy singleton; only the exact (case-insensitive) names 'datanode' (BalancingPolicy.Node) and 'blockpool' (BalancingPolicy.Pool) are accepted. Any other string throws IllegalArgumentException echoing the input. 'datanode' balances per DataNode; 'blockpool' balances per block pool, relevant only for federated/combined namespaces.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancingPolicy.java:87

   *          or return null if the datanode does not have such storage type.
   */
  abstract Double getUtilization(DatanodeStorageReport r, StorageType t);
  
  @Override
  public String toString() {
    return BalancingPolicy.class.getSimpleName()
        + "." + getClass().getSimpleName();
  }

  /** Get all {@link BalancingPolicy} instances*/
  static BalancingPolicy parse(String s) {
    final BalancingPolicy [] all = {BalancingPolicy.Node.INSTANCE,
                                    BalancingPolicy.Pool.INSTANCE};
    for(BalancingPolicy p : all) {
      if (p.getName().equalsIgnoreCase(s))
        return p;
    }
    throw new IllegalArgumentException("Cannot parse string \"" + s + "\"");
  }

  /**
   * Cluster is balanced if each node is balanced.
   */
  static class Node extends BalancingPolicy {
    static final Node INSTANCE = new Node();
    private Node() {}

    @Override
    String getName() {
      return "datanode";
    }

    @Override
    void accumulateSpaces(DatanodeStorageReport r) {
      for(StorageReport s : r.getStorageReports()) {
        final StorageType t = s.getStorage().getStorageType();

View on GitHub (pinned to 2add963021)

Solutions

  1. Use exactly 'hdfs balancer -policy datanode' or 'hdfs balancer -policy blockpool' (case-insensitive)
  2. For single-block-pool clusters simply omit -policy; datanode is the default
  3. Trim stray whitespace/quotes in automated argument construction

Example fix

# before
hdfs balancer -policy node

# after
hdfs balancer -policy datanode
Defensive patterns

Strategy: type-guard

Type guard

static boolean isValidBalancingPolicy(String s) {
  return "datanode".equalsIgnoreCase(s) || "blockpool".equalsIgnoreCase(s);
}

Try / catch

catch (IllegalArgumentException e) { System.err.println("-policy must be 'datanode' or 'blockpool'"); System.exit(-1); }

Prevention

When it happens

Trigger: hdfs balancer -policy node (or 'pool', 'DN', 'block', an empty string, or trailing whitespace) - anything other than 'datanode' or 'blockpool' after case-folding.

Common situations: Shortening the policy name in scripts; using the value 'node' which looks natural but is wrong; config/args carried over from tooling that names the policies differently.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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