oracle/graal · warning · InvalidArgumentException

invalid boolean value: "%s"

Error message

invalid boolean value: "%s"

What it means

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.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/util/args/BooleanValue.java:55

    public BooleanValue(String name, boolean defaultValue, String help) {
        super(name, defaultValue, help);
    }

    @Override
    public boolean parseValue(String arg) throws InvalidArgumentException {
        if (arg == null) {
            throw new InvalidArgumentException(getName(), "no value provided");
        }
        switch (arg.toLowerCase(Locale.US)) {
            case "true":
                value = true;
                break;
            case "false":
                value = false;
                break;
            default:
                throw new InvalidArgumentException(getName(), String.format("invalid boolean value: \"%s\"", arg));
        }
        return true;
    }
}

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Use exactly 'true' or 'false' (any case works — it is lowercased first), with no surrounding whitespace.
  2. Quote shell variables and trim programmatically-built arg strings: "-opt=" + flag.trim().
  3. Catch InvalidArgumentException and print getName() plus the option help to guide the user.

Example fix

# before
FLAG=$(grep enabled config.txt | cut -d= -f2)  # yields "1"
$ tool -opt=$FLAG

# after
$ tool -opt=true   # or normalize: [ "$FLAG" = "1" ] && FLAG=true
Defensive patterns

Strategy: validation

Validate before calling

// Normalize common truthy/falsy spellings before the parser sees them
static String normalizeBool(String raw) {
    if (raw == null) return null;
    String t = raw.trim().toLowerCase(Locale.US);
    return switch (t) {
        case "1", "yes", "on" -> "true";
        case "0", "no", "off" -> "false";
        default -> t;
    };
}

Type guard

static boolean isStrictBoolean(String s) {
    if (s == null) return false;
    String t = s.toLowerCase(Locale.US);
    return t.equals("true") || t.equals("false");
}

Try / catch

try {
    cmd.parse(args);
} catch (InvalidArgumentException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("invalid boolean value")) {
        System.err.println(e.getOption() + " accepts only true|false (got: " + e.getValue() + ")");
    } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/171ca2211f0cbffc. Report an issue: GitHub.