{"record":{"id":"abfe955f3c0b840b","repo":"apache/hadoop","slug":"cannot-parse-string-s","errorCode":null,"errorMessage":"Cannot parse string \"{s}\"","messagePattern":"Cannot parse string \"(.+?)\"","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancingPolicy.java","lineNumber":87,"sourceCode":"   *          or return null if the datanode does not have such storage type.\n   */\n  abstract Double getUtilization(DatanodeStorageReport r, StorageType t);\n  \n  @Override\n  public String toString() {\n    return BalancingPolicy.class.getSimpleName()\n        + \".\" + getClass().getSimpleName();\n  }\n\n  /** Get all {@link BalancingPolicy} instances*/\n  static BalancingPolicy parse(String s) {\n    final BalancingPolicy [] all = {BalancingPolicy.Node.INSTANCE,\n                                    BalancingPolicy.Pool.INSTANCE};\n    for(BalancingPolicy p : all) {\n      if (p.getName().equalsIgnoreCase(s))\n        return p;\n    }\n    throw new IllegalArgumentException(\"Cannot parse string \\\"\" + s + \"\\\"\");\n  }\n\n  /**\n   * Cluster is balanced if each node is balanced.\n   */\n  static class Node extends BalancingPolicy {\n    static final Node INSTANCE = new Node();\n    private Node() {}\n\n    @Override\n    String getName() {\n      return \"datanode\";\n    }\n\n    @Override\n    void accumulateSpaces(DatanodeStorageReport r) {\n      for(StorageReport s : r.getStorageReports()) {\n        final StorageType t = s.getStorage().getStorageType();","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/balancer/BalancingPolicy.java#L69-L105","documentation":"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.","triggerScenarios":"hdfs balancer -policy node (or 'pool', 'DN', 'block', an empty string, or trailing whitespace) - anything other than 'datanode' or 'blockpool' after case-folding.","commonSituations":"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.","solutions":["Use exactly 'hdfs balancer -policy datanode' or 'hdfs balancer -policy blockpool' (case-insensitive)","For single-block-pool clusters simply omit -policy; datanode is the default","Trim stray whitespace/quotes in automated argument construction"],"exampleFix":"# before\nhdfs balancer -policy node\n\n# after\nhdfs balancer -policy datanode","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static boolean isValidBalancingPolicy(String s) {\n  return \"datanode\".equalsIgnoreCase(s) || \"blockpool\".equalsIgnoreCase(s);\n}","tryCatchPattern":"catch (IllegalArgumentException e) { System.err.println(\"-policy must be 'datanode' or 'blockpool'\"); System.exit(-1); }","preventionTips":["Whitelist the two legal values in wrappers with isValidBalancingPolicy","Omit -policy on single-block-pool clusters; the datanode default is correct"],"tags":["hdfs","balancer","cli","argument-validation","enum-value"],"backgroundTag":"invalid-enum-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}