zaproxy/zaproxy · warning · IllegalArgumentException

Failed to create enum for '{}' using '{}'. Valid values: {}

Error message

Failed to create enum for '{}' using '{}'. Valid values: {}

What it means

AbstractParam.getEnum reads a config string and converts it to an enum via Enum.valueOf; when the stored value is not a valid constant name it logs this warning listing the valid values, and the method then returns the provided defaultValue (fall-through after the catch). This protects ZAP from crashing on bad enum config values.

Source

Thrown at zap/src/main/java/org/parosproxy/paros/common/AbstractParam.java:256

    /**
     * Gets an enum value from the given configuration key.
     *
     * <p>The default value is returned if the key doesn't exist or it's not an enum value.
     *
     * @param key the configuration key.
     * @param defaultValue the default value, if the key doesn't exist or it's not an enum value.
     * @return the value of the configuration, or default value.
     * @throws NullPointerException if the given default value is {@code null}.
     * @since 2.13.0
     */
    protected <T extends Enum<T>> T getEnum(String key, T defaultValue) {
        String value = getString(key, defaultValue.name());
        @SuppressWarnings("unchecked")
        Class<T> enumType = (Class<T>) defaultValue.getClass();
        try {
            return Enum.valueOf(enumType, value);
        } catch (IllegalArgumentException e) {
            LOGGER.warn(
                    "Failed to create enum for '{}' using '{}'. Valid values: {}",
                    key,
                    value,
                    getValues(enumType));
        }
        return defaultValue;
    }

    private static <T extends Enum<T>> List<String> getValues(Class<T> enumType) {
        try {
            Method valuesMethod = enumType.getDeclaredMethod("values");
            @SuppressWarnings("unchecked")
            T[] values = (T[]) valuesMethod.invoke(enumType);
            return Stream.of(values).map(Enum::name).collect(Collectors.toList());
        } catch (Exception e) {
            LOGGER.error("Error getting enum values:", e);
        }

View on GitHub (pinned to 9d1970a436)

Solutions

  1. Fix the config value to one of the listed valid constants (they are printed in the warning)
  2. Delete the key so the code persists the default again
  3. Update the addon/ZAP version so old names map to new constants

Example fix

// before
<option>sslerror</option>
// after
<option>SSL_ERROR</option>
Defensive patterns

Strategy: validation

Validate before calling

String stored = config.getString(key, "");
boolean valid = false;
for (Enum<?> c : defaultValue.getDeclaringClass().getEnumConstants()) {
    if (c.name().equals(stored)) { valid = true; break; }
}
if (!valid) config.setProperty(key, defaultValue.name()); // reset before load

Try / catch

MyEnum val = param.getEnum("some.key", MyEnum.DEFAULT);
// getEnum already falls back to the default; verify with a log if strictness is needed

Prevention

When it happens

Trigger: A config key that should hold an enum constant name (case-sensitive) contains a renamed, removed, misspelled, or differently-cased value; e.g. stored "auto" while the enum defines "AUTO"; old config from a previous ZAP/addon version with a since-renamed constant.

Common situations: Upgrading ZAP or an addon where enum constants were renamed; users editing config values by hand; configs synced between machines running different versions.

Related errors


AI-assisted analysis of zaproxy/zaproxy@9d1970a436 (2026-09-05). Data as JSON: /api/errors/639d971ab0a6101d. Report an issue: GitHub.