oracle/graal · error · IllegalArgumentException

Wrong value for option '%s'

Error message

Wrong value for option '%s'

What it means

Thrown by OptionsParser.parseOptionValue when the option's declared value type is none of the supported kinds (Boolean, String, Enum, EconomicSet, Float, Double, Integer, Long). It is a defensive branch: it indicates an OptionDescriptor was declared with an option type the generic parser does not know how to convert from a String, which is essentially a programming error in the option declaration rather than a user input mistake.

Source

Thrown at compiler/src/jdk.graal.compiler.options/src/jdk/graal/compiler/options/OptionsParser.java:260

            } else if (Enum.class.isAssignableFrom(optionType)) {
                value = ((EnumOptionKey<?>) desc.getOptionKey()).valueOf(valueString);
            } else if (optionType == EconomicSet.class) {
                value = ((EnumMultiOptionKey<?>) desc.getOptionKey()).valueOf(valueString);
            } else {
                if (valueString.isEmpty()) {
                    throw new IllegalArgumentException("Non empty value required for option '" + desc.getName() + "'");
                }
                try {
                    if (optionType == Float.class) {
                        value = Float.parseFloat(valueString);
                    } else if (optionType == Double.class) {
                        value = Double.parseDouble(valueString);
                    } else if (optionType == Integer.class) {
                        value = (int) parseLong(valueString);
                    } else if (optionType == Long.class) {
                        value = parseLong(valueString);
                    } else {
                        throw new IllegalArgumentException("Wrong value for option '" + desc.getName() + "'");
                    }
                } catch (NumberFormatException nfe) {
                    throw new IllegalArgumentException("Value for option '" + desc.getName() + "' has invalid number format: " + valueString);
                }
            }
        }
        return value;
    }

    private static long parseLong(String v) {
        String valueString = v.toLowerCase(Locale.ROOT);
        long scale = 1;
        if (valueString.endsWith("k")) {
            scale = 1024L;
        } else if (valueString.endsWith("m")) {
            scale = 1024L * 1024L;
        } else if (valueString.endsWith("g")) {
            scale = 1024L * 1024L * 1024L;

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Declare the option with one of the supported types (Boolean, String, an enum, Float, Double, Integer, Long) or an EnumMultiOptionKey set.
  2. If a custom type is required, parse the String yourself and call desc.getOptionKey().update(values, parsedObject) directly, bypassing the generic String branch.
  3. Check desc.getOptionValueType() for the offending option to confirm which type fell through.

Example fix

// before
OptionKey<Short> MyOpt = OptionKey.stub(...); // unsupported type

// after
OptionKey<Integer> MyOpt = new OptionKey<>(0); // supported; scale at use site
Defensive patterns

Strategy: validation

Validate before calling

static final Set<Class<?>> SUPPORTED = Set.of(Boolean.class, String.class, Float.class, Double.class, Integer.class, Long.class);

boolean isParserSupported(OptionDescriptor desc) {
    Class<?> t = desc.getOptionValueType();
    return SUPPORTED.contains(t) || Enum.class.isAssignableFrom(t) || EconomicSet.class.isAssignableFrom(t);
}

Prevention

When it happens

Trigger: A custom OptionKey subclass with an unsupported boxed type (e.g. Short, BigDecimal, or a custom class) whose descriptor reaches the generic string-parsing path in parseOptionValue. Users cannot trigger this through ordinary -Dgraal flags because shipped options all use supported types.

Common situations: Writing a new Graal option with an exotic value type and relying on OptionsParser to parse it from a String; passing a programmatically-built OptionDescriptor for a custom option system modeled on Graal's.

Related errors


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