{"record":{"id":"171ca2211f0cbffc","repo":"oracle/graal","slug":"invalid-boolean-value-s","errorCode":null,"errorMessage":"invalid boolean value: \"%s\"","messagePattern":"invalid boolean value: \"(.+?)\"","errorType":"validation","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"warning","filePath":"compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/util/args/BooleanValue.java","lineNumber":55,"sourceCode":"\n    public BooleanValue(String name, boolean defaultValue, String help) {\n        super(name, defaultValue, help);\n    }\n\n    @Override\n    public boolean parseValue(String arg) throws InvalidArgumentException {\n        if (arg == null) {\n            throw new InvalidArgumentException(getName(), \"no value provided\");\n        }\n        switch (arg.toLowerCase(Locale.US)) {\n            case \"true\":\n                value = true;\n                break;\n            case \"false\":\n                value = false;\n                break;\n            default:\n                throw new InvalidArgumentException(getName(), String.format(\"invalid boolean value: \\\"%s\\\"\", arg));\n        }\n        return true;\n    }\n}\n","sourceCodeStart":37,"sourceCodeEnd":60,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/util/args/BooleanValue.java#L37-L60","documentation":"InvalidArgumentException from BooleanValue.parseValue: a value string was provided but, lowercased with Locale.US, it is neither 'true' nor 'false'. The parser is deliberately strict — '1'/'0', 'yes'/'no', 'on'/'off', and mixed-case like 'True' are accepted only when they lowercase exactly to true/false; everything else is rejected with the offending string quoted in the message.","triggerScenarios":"Passing '-opt=1', '-opt=yes', '-opt=TRUE ' (trailing whitespace), or '-opt=on' to a CLI built on BooleanValue — the switch default fires and throws with String.format(\"invalid boolean value: \\\"%s\\\"\", arg).","commonSituations":"Users habitually using 1/0 from shell scripting ($? expansion); whitespace from unquoted shell variables; YAML/env-file booleans (true/false with quotes) passed through verbatim.","solutions":["Use exactly 'true' or 'false' (any case works — it is lowercased first), with no surrounding whitespace.","Quote shell variables and trim programmatically-built arg strings: \"-opt=\" + flag.trim().","Catch InvalidArgumentException and print getName() plus the option help to guide the user."],"exampleFix":"# before\nFLAG=$(grep enabled config.txt | cut -d= -f2)  # yields \"1\"\n$ tool -opt=$FLAG\n\n# after\n$ tool -opt=true   # or normalize: [ \"$FLAG\" = \"1\" ] && FLAG=true","handlingStrategy":"validation","validationCode":"// Normalize common truthy/falsy spellings before the parser sees them\nstatic String normalizeBool(String raw) {\n    if (raw == null) return null;\n    String t = raw.trim().toLowerCase(Locale.US);\n    return switch (t) {\n        case \"1\", \"yes\", \"on\" -> \"true\";\n        case \"0\", \"no\", \"off\" -> \"false\";\n        default -> t;\n    };\n}","typeGuard":"static boolean isStrictBoolean(String s) {\n    if (s == null) return false;\n    String t = s.toLowerCase(Locale.US);\n    return t.equals(\"true\") || t.equals(\"false\");\n}","tryCatchPattern":"try {\n    cmd.parse(args);\n} catch (InvalidArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"invalid boolean value\")) {\n        System.err.println(e.getOption() + \" accepts only true|false (got: \" + e.getValue() + \")\");\n    } else throw e;\n}","preventionTips":["Use exactly true/false on the command line; avoid 1/0/yes/on unless you normalize first.","Quote and trim shell-derived values feeding options.","Document accepted boolean syntax next to each flag."],"tags":["cli","arguments","boolean","parsing","options"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}