{"record":{"id":"c5bc66943f4ef12e","repo":"oracle/graal","slug":"boolean-option-s-must-have-value-true-or-fal","errorCode":null,"errorMessage":"Boolean option '%s' must have value \"true\" or \"false\", not \"%s\"","messagePattern":"Boolean option '(.+?)' must have value \"true\" or \"false\", not \"(.+?)\"","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.options/src/jdk/graal/compiler/options/OptionsParser.java","lineNumber":238,"sourceCode":"     * Parses a given option value with a known descriptor.\n     */\n    public static Object parseOptionValue(OptionDescriptor desc, Object uncheckedValue) {\n        Class<?> optionType = desc.getOptionValueType();\n        Object value;\n        if (!(uncheckedValue instanceof String valueString)) {\n            if (optionType != uncheckedValue.getClass()) {\n                String type = optionType.getSimpleName();\n                throw new IllegalArgumentException(type + \" option '\" + desc.getName() + \"' must have \" + type + \" value, not \" + uncheckedValue.getClass() + \" [toString: \" + uncheckedValue + \"]\");\n            }\n            value = uncheckedValue;\n        } else {\n            if (optionType == Boolean.class) {\n                if (\"true\".equals(valueString)) {\n                    value = Boolean.TRUE;\n                } else if (\"false\".equals(valueString)) {\n                    value = Boolean.FALSE;\n                } else {\n                    throw new IllegalArgumentException(\"Boolean option '\" + desc.getName() + \"' must have value \\\"true\\\" or \\\"false\\\", not \\\"\" + uncheckedValue + \"\\\"\");\n                }\n            } else if (optionType == String.class) {\n                value = valueString;\n            } else if (Enum.class.isAssignableFrom(optionType)) {\n                value = ((EnumOptionKey<?>) desc.getOptionKey()).valueOf(valueString);\n            } else if (optionType == EconomicSet.class) {\n                value = ((EnumMultiOptionKey<?>) desc.getOptionKey()).valueOf(valueString);\n            } else {\n                if (valueString.isEmpty()) {\n                    throw new IllegalArgumentException(\"Non empty value required for option '\" + desc.getName() + \"'\");\n                }\n                try {\n                    if (optionType == Float.class) {\n                        value = Float.parseFloat(valueString);\n                    } else if (optionType == Double.class) {\n                        value = Double.parseDouble(valueString);\n                    } else if (optionType == Integer.class) {\n                        value = (int) parseLong(valueString);","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.options/src/jdk/graal/compiler/options/OptionsParser.java#L220-L256","documentation":"Thrown by OptionsParser.parseOptionValue when a Boolean-typed option receives a String value that is neither exactly 'true' nor 'false'. The parser is deliberately strict: no 'yes'/'no', '1'/'0', or mixed-case variants are accepted, because these flags map directly to -Dgraal.<Name>=<value> JVM properties.","triggerScenarios":"Passing 'True', 'TRUE', '1', 'yes', or '' as the string value of a Boolean option, e.g. parseOptions(\"PrintGraph=Yes\", ...) or -Dgraal.PrintGraph=1. Only exact lowercase \"true\"/\"false\" match.","commonSituations":"Shell scripts upper-casing values (${FLAG^^}); YAML/JSON config with boolean true serialized as 'True' or 'yes'; environment variables defaulting to '1'; locale-specific or whitespace-padded values ('true ') failing the equals check.","solutions":["Use exactly true or false, lowercase, with no surrounding whitespace.","Normalize before passing: value.trim().toLowerCase(Locale.ROOT), and map 1/0/yes/no to true/false in your own config layer.","If the value comes from an env var, document that only 'true'/'false' are accepted or convert it at the boundary."],"exampleFix":"// before\nOptionsParser.parseOptionSettingTo(\"PrintGraph=True\", values);\n\n// after\nOptionsParser.parseOptionSettingTo(\"PrintGraph=true\", values);","handlingStrategy":"validation","validationCode":"String normalizeBoolean(String raw) {\n    String v = raw.trim().toLowerCase(Locale.ROOT);\n    switch (v) {\n        case \"true\": case \"yes\": case \"1\": return \"true\";\n        case \"false\": case \"no\": case \"0\": return \"false\";\n        default: throw new IllegalArgumentException(\"Not a boolean: \" + raw);\n    }\n}\n\nOptionsParser.parseOptionSettingTo(name + \"=\" + normalizeBoolean(rawValue), dst);","typeGuard":"boolean isGraalBooleanLiteral(String s) {\n    return \"true\".equals(s) || \"false\".equals(s);\n}","tryCatchPattern":"try {\n    OptionsParser.parseOptionSettingTo(setting, dst);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Boolean option\")) {\n        throw new ConfigException(\"Option value '\" + setting + \"' must be exactly true or false (lowercase)\", e);\n    }\n    throw e;\n}","preventionTips":["Lowercase and trim boolean values at your config boundary before building -Dgraal flags.","Map 1/0/yes/no to true/false yourself; Graal accepts only the exact literals.","Add unit tests asserting emitted flag strings for boolean options."],"tags":["graalvm","options","boolean","validation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}