{"record":{"id":"ddec4ef04b5d2268","repo":"apache/hadoop","slug":"failed-to-parse-str-to-boolean","errorCode":null,"errorMessage":"Failed to parse \"{str}\" to Boolean.","messagePattern":"Failed to parse \"(.+?)\" to Boolean\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/BooleanParam.java","lineNumber":53,"sourceCode":"  /** The domain of the parameter. */\n  static final class Domain extends Param.Domain<Boolean> {\n    Domain(final String paramName) {\n      super(paramName);\n    }\n\n    @Override\n    public String getDomain() {\n      return \"<\" + NULL + \" | boolean>\";\n    }\n\n    @Override\n    Boolean parse(final String str) {\n      if (TRUE.equalsIgnoreCase(str)) {\n        return true;\n      } else if (FALSE.equalsIgnoreCase(str)) {\n        return false;\n      }\n      throw new IllegalArgumentException(\"Failed to parse \\\"\" + str\n          + \"\\\" to Boolean.\");\n    }\n  }\n}\n","sourceCodeStart":35,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-client/src/main/java/org/apache/hadoop/hdfs/web/resources/BooleanParam.java#L35-L58","documentation":"BooleanParam.Domain.parse accepts only the case-insensitive literals 'true' and 'false'; any other string in a WebHDFS URL boolean parameter throws IllegalArgumentException('Failed to parse \"<str>\" to Boolean.'). WebHDFS encodes FileSystem options as HTTP query params (overwrite, recursive, createparent, noredirect, ...), and this parser is used when those param values are materialized from URL strings. Values like 1/0, yes/no, or ON are rejected.","triggerScenarios":"Hand-building a WebHDFS REST URL with a boolean param spelled wrongly, e.g. ...?op=MKDIRS&recursive=1 or ?op=CREATE&overwrite=yes; or programmatically constructing BooleanParam-style params from unchecked user input. Server-side (NameNode/httpfs) the parse failure surfaces as an HTTP 400 with the IllegalArgumentException message.","commonSituations":"Scripts and curl clients translating CLI flags (0/1, yes/no) directly into WebHDFS URLs; clients porting from S3/GS query conventions; typo'd values (TRUE works, but 'ture' does not); passing empty values (&overwrite=).","solutions":["Use only true or false (any case) as the value of boolean query params, or omit the param to take its default","Prefer the FileSystem API (FileSystem.mkdirs/rename/create with options) — it builds correctly encoded URLs for you","Normalize/validate boolean inputs before embedding them in URLs (see validation code)","URL-encode values and double-check the param name spelled exactly as the op expects"],"exampleFix":"// before\nString url = \"http://nn:9870/webhdfs/v1/user/x?op=MKDIRS&recursive=1\"; // 400: Failed to parse \"1\" to Boolean\n// after\nString url = \"http://nn:9870/webhdfs/v1/user/x?op=MKDIRS&recursive=true\";","handlingStrategy":"validation","validationCode":"static String toWebhdfsBoolean(String raw) {\n  if (\"true\".equalsIgnoreCase(raw) || \"false\".equalsIgnoreCase(raw)) {\n    return raw.toLowerCase(Locale.ROOT);\n  }\n  throw new IllegalArgumentException(\n      \"WebHDFS boolean params accept only true/false, got: \" + raw);\n}","typeGuard":"static boolean isBooleanParamValue(String s) {\n  return s != null && (\"true\".equalsIgnoreCase(s) || \"false\".equalsIgnoreCase(s));\n}","tryCatchPattern":"try {\n  conn.connect();\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"to Boolean\")) {\n    // URL boolean param was invalid: fix the query string, do not retry\n  }\n}","preventionTips":["Build WebHDFS URLs with the FileSystem API or the param classes instead of string concatenation","Map CLI flags through a strict true/false normalizer before embedding in URLs","Omit optional boolean params to use their default instead of sending placeholder values"],"tags":["webhdfs","query-param","boolean-parsing","rest"],"backgroundTag":"invalid-query-parameter","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}