{"record":{"id":"639d971ab0a6101d","repo":"zaproxy/zaproxy","slug":"failed-to-create-enum-for-using-valid-v","errorCode":null,"errorMessage":"Failed to create enum for '{}' using '{}'. Valid values: {}","messagePattern":"Failed to create enum for '(.+?)' using '(.+?)'\\. Valid values: (.+?)","errorType":"console","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"zap/src/main/java/org/parosproxy/paros/common/AbstractParam.java","lineNumber":256,"sourceCode":"\n    /**\n     * Gets an enum value from the given configuration key.\n     *\n     * <p>The default value is returned if the key doesn't exist or it's not an enum value.\n     *\n     * @param key the configuration key.\n     * @param defaultValue the default value, if the key doesn't exist or it's not an enum value.\n     * @return the value of the configuration, or default value.\n     * @throws NullPointerException if the given default value is {@code null}.\n     * @since 2.13.0\n     */\n    protected <T extends Enum<T>> T getEnum(String key, T defaultValue) {\n        String value = getString(key, defaultValue.name());\n        @SuppressWarnings(\"unchecked\")\n        Class<T> enumType = (Class<T>) defaultValue.getClass();\n        try {\n            return Enum.valueOf(enumType, value);\n        } catch (IllegalArgumentException e) {\n            LOGGER.warn(\n                    \"Failed to create enum for '{}' using '{}'. Valid values: {}\",\n                    key,\n                    value,\n                    getValues(enumType));\n        }\n        return defaultValue;\n    }\n\n    private static <T extends Enum<T>> List<String> getValues(Class<T> enumType) {\n        try {\n            Method valuesMethod = enumType.getDeclaredMethod(\"values\");\n            @SuppressWarnings(\"unchecked\")\n            T[] values = (T[]) valuesMethod.invoke(enumType);\n            return Stream.of(values).map(Enum::name).collect(Collectors.toList());\n        } catch (Exception e) {\n            LOGGER.error(\"Error getting enum values:\", e);\n        }","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/zaproxy/zaproxy/blob/9d1970a436b1b189bfb588fc88864c80d9baf6a5/zap/src/main/java/org/parosproxy/paros/common/AbstractParam.java#L238-L274","documentation":"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.","triggerScenarios":"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.","commonSituations":"Upgrading ZAP or an addon where enum constants were renamed; users editing config values by hand; configs synced between machines running different versions.","solutions":["Fix the config value to one of the listed valid constants (they are printed in the warning)","Delete the key so the code persists the default again","Update the addon/ZAP version so old names map to new constants"],"exampleFix":"// before\n<option>sslerror</option>\n// after\n<option>SSL_ERROR</option>","handlingStrategy":"validation","validationCode":"String stored = config.getString(key, \"\");\nboolean valid = false;\nfor (Enum<?> c : defaultValue.getDeclaringClass().getEnumConstants()) {\n    if (c.name().equals(stored)) { valid = true; break; }\n}\nif (!valid) config.setProperty(key, defaultValue.name()); // reset before load","typeGuard":null,"tryCatchPattern":"MyEnum val = param.getEnum(\"some.key\", MyEnum.DEFAULT);\n// getEnum already falls back to the default; verify with a log if strictness is needed","preventionTips":["Persist enum.name() only, never toString or localized labels","Reset keys to defaults when upgrading across versions with renamed constants","Case-sensitive: store constants in exact uppercase"],"tags":["configuration","zap","enum","type-conversion"],"backgroundTag":"invalid-enum-config-value","analyzedSha":"9d1970a436b1b189bfb588fc88864c80d9baf6a5","analyzedAt":"2026-09-05T19:26:59.356Z","contentChangedAt":"2026-09-05T19:26:59.356Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}