oracle/graal · error · InvalidArgumentException

no choice named '%s'

Error message

no choice named '%s'

What it means

Thrown by MultiChoiceValue.parseValue when the parsed string is not a key in the choices map, i.e. no alternative with that name was registered via addChoice before parsing. It signals a typo or an unregistered alternative for a multi-choice option.

Source

Thrown at compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/util/args/MultiChoiceValue.java:58

    private String defaultChoice = null;

    public MultiChoiceValue(String name, String help) {
        super(name, help);
    }

    public MultiChoiceValue(String name, T defaultValue, String help) {
        super(name, defaultValue, help);
    }

    @Override
    public boolean parseValue(String arg) throws InvalidArgumentException {
        if (arg == null) {
            value = defaultValue;
            return false;
        }
        value = choices.get(arg);
        if (value == null) {
            throw new InvalidArgumentException(getName(), String.format("no choice named '%s'", arg));
        }
        return true;
    }

    /**
     * Adds a choice to the set of alternatives for this option.
     *
     * @param name user-visible name for the alternative, as will be parsed from the command-line.
     * @param choiceValue value that will be returned if the given choice is selected.
     * @param help help text for the choice in question.
     * @return {@code this}
     */
    public MultiChoiceValue<T> addChoice(String name, T choiceValue, String help) {
        choices.put(name, choiceValue);
        choiceHelp.put(name, help);
        if (choiceValue.equals(defaultValue)) {
            defaultChoice = name;
        }

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. List the valid choices for the option (check the option's help text or its addChoice calls) and use an exact-match name
  2. Fix spelling/capitalization of the passed value
  3. If the choice genuinely should exist, call addChoice(name, value, help) on the MultiChoiceValue before parsing
  4. Omit the option entirely to fall back to the default value

Example fix

// before
MultiChoiceValue<String> mode = new MultiChoiceValue<>("Mode", "a", "help");
mode.parseValue("fast");            // InvalidArgumentException: no choice named 'fast'

// after
MultiChoiceValue<String> mode = new MultiChoiceValue<>("Mode", "a", "help").addChoice("fast", "F", "fast mode");
mode.parseValue("fast");
Defensive patterns

Strategy: validation

Validate before calling

if (!choiceValue.choices().containsKey(arg)) { // expose or mirror the choices map
    throw new IllegalArgumentException("unknown choice '" + arg + "', valid: " + choiceValue.choices().keySet());
}

Try / catch

catch (InvalidArgumentException e) { fall back to defaultValue explicitly: value = defaultValue; }

Prevention

When it happens

Trigger: Calling parseValue(arg) on a MultiChoiceValue where arg does not exactly match any name passed to addChoice(...) — including case mismatches, or calling parseValue before any addChoice calls were made. Only a null arg silently resets to the default; every other unknown string throws.

Common situations: Misspelling a choice on the command line (-D:SomeOption=inlien instead of inline), using different capitalization than the registered name, or a version change where a choice name was renamed/removed while old scripts still pass it.

Related errors


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