{"record":{"id":"9bedeb540641197c","repo":"apache/hadoop","slug":"invalid-value-0-must-be-a-boolean","errorCode":null,"errorMessage":"Invalid value [{0}], must be a boolean","messagePattern":"Invalid value \\[(.+?)\\], must be a boolean","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/BooleanParam.java","lineNumber":39,"sourceCode":"import org.apache.hadoop.classification.InterfaceAudience;\n\nimport java.text.MessageFormat;\n\n@InterfaceAudience.Private\npublic abstract class BooleanParam extends Param<Boolean> {\n\n  public BooleanParam(String name, Boolean defaultValue) {\n    super(name, defaultValue);\n  }\n\n  @Override\n  protected Boolean parse(String str) throws Exception {\n    if (str.equalsIgnoreCase(\"true\")) {\n      return true;\n    } else if (str.equalsIgnoreCase(\"false\")) {\n      return false;\n    }\n    throw new IllegalArgumentException(MessageFormat.format(\"Invalid value [{0}], must be a boolean\", str));\n  }\n\n  @Override\n  protected String getDomain() {\n    return \"a boolean\";\n  }\n}\n","sourceCodeStart":21,"sourceCodeEnd":47,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-httpfs/src/main/java/org/apache/hadoop/lib/wsrs/BooleanParam.java#L21-L47","documentation":"org.apache.hadoop.lib.wsrs.BooleanParam.parse (BooleanParam.java:39) accepts only the case-insensitive literals \"true\" and \"false\" for REST query parameters; anything else throws IllegalArgumentException(\"Invalid value [...], must be a boolean\"). In httpfs, BooleanParam backs the WebHDFS query parameters data, noredirect, recursive, overwrite and allusers (HttpFSParametersProvider). Note that on the normal JAX-RS path this exception is caught by Param.parseParam and rewrapped as the 'Parameter [...], invalid value [...], value must be [a boolean]' message (error 3685), so the raw text surfaces only when parse() is called directly, e.g. in unit tests.","triggerScenarios":"A WebHDFS/httpfs request like ?op=DELETE&recursive=1 or ?op=CREATE&overwrite=yes — '1', '0', 'yes', 'no', 'on' are all rejected; only true/false (any case) pass. Directly calling parse(\"1\") on a BooleanParam subclass in tests reproduces the raw message.","commonSituations":"Scripts ported from shell conventions where 0/1 mean false/true; clients sending 'Yes'/'on'; URL-encoding damage appending %0A or spaces to the value.","solutions":["Send only true or false (case-insensitive) for boolean params: recursive=true, overwrite=false.","Fix the client serializer to emit boolean literals, never 1/0/yes/no.","Trim and URL-decode values before building the request URL.","For custom BooleanParam subclasses invoked directly, keep the parse() contract: true/false only."],"exampleFix":"# before\ncurl 'http://nn:14000/webhdfs/v1/dir?op=DELETE&user.name=hdfs&recursive=1'   # 400\n\n# after\ncurl 'http://nn:14000/webhdfs/v1/dir?op=DELETE&user.name=hdfs&recursive=true' # 200","handlingStrategy":"validation","validationCode":"String v = queryParams.get(\"recursive\");\nif (v != null && !v.equalsIgnoreCase(\"true\") && !v.equalsIgnoreCase(\"false\")) {\n  throw new IllegalArgumentException(\"recursive must be true|false, got \" + v);\n}","typeGuard":"static boolean isBooleanLiteral(String s) {\n  return \"true\".equalsIgnoreCase(s) || \"false\".equalsIgnoreCase(s);\n}","tryCatchPattern":"try {\n  param.parseParam(value);\n} catch (IllegalArgumentException ex) {\n  // message already states the domain ('a boolean'); map to HTTP 400\n  return badRequest(ex.getMessage());\n}","preventionTips":["Serialize boolean query params only as true/false.","Never send 1/0/yes/on for WebHDFS booleans.","Mirror the server domain ('a boolean') in client-side validation."],"tags":["java","hadoop","httpfs","rest","webhdfs","boolean","query-string"],"backgroundTag":"invalid-boolean-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}