{"record":{"id":"36018f34e8a715ae","repo":"apache/pulsar","slug":"invalid-value-for-enum","errorCode":null,"errorMessage":"Invalid value '' for enum ","messagePattern":"Invalid value '' for enum ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java","lineNumber":113,"sourceCode":"\n        // Lookup the suitable converter.\n        String converterId = from.getClass().getName() + \"_\" + to.getName();\n        Method converter = CONVERTERS.get(converterId);\n\n        if (to.isEnum()) {\n            // Converting string to enum\n            DeserializationConfig deserializationConfig =\n                    ObjectMapperFactory.getMapper().getObjectMapper().getDeserializationConfig();\n            // No replacement API available in Jackson 2.x\n            AnnotatedClass annotatedEnum = AnnotatedClassResolver.resolve(\n                    deserializationConfig,\n                    deserializationConfig.getTypeFactory().constructType(to),\n                    deserializationConfig\n            );\n            EnumResolver r = EnumResolver.constructUsingToString(deserializationConfig, annotatedEnum);\n            T value = (T) r.findEnum((String) from);\n            if (value == null) {\n                throw new RuntimeException(\"Invalid value '\" + from + \"' for enum \" + to);\n            }\n            return value;\n        }\n\n        if (converter == null) {\n            throw new UnsupportedOperationException(\"Cannot convert from \" + from.getClass().getName() + \" to \"\n                    + to.getName() + \". Requested converter does not exist.\");\n        }\n\n        // Convert the value.\n        try {\n            Object val = converter.invoke(to, from);\n            return to.cast(val);\n        } catch (Exception e) {\n            throw new RuntimeException(\"Cannot convert from \" + from.getClass().getName() + \" to \" + to.getName()\n                    + \". Conversion failed with \" + e.getMessage(), e);\n        }\n    }","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java#L95-L131","documentation":"Thrown by FieldParser.enum conversion when a string value cannot be resolved to a constant of the target enum type — Jackson's EnumResolver.findEnum returns null and the parser raises a RuntimeException naming both the invalid value and the enum type. This is used when mapping string configuration into typed fields.","triggerScenarios":"Calling FieldParser.value/convert (directly or via stringToList/stringToSet/stringToMap) with a string that is not an exact enum constant name of the target type — including wrong case, trailing whitespace, or a constant added only in newer Pulsar versions.","commonSituations":"Configuration files (broker/client/service_unit yaml) with a misspelled or mis-cased enum value; config copied from docs of a different Pulsar version where the enum constant changed; extra whitespace or quotes in the value; using display names instead of the enum constant name.","solutions":["Fix the configured value to exactly match an enum constant name (case-sensitive, no whitespace)","Check the enum's declared constants (e.g. print or read the target enum class) and pick a valid one","Align configuration with the Pulsar version in use — verify the constant exists in that release","Pre-validate the string with EnumUtils/Enum.valueOf inside a try-catch before assigning the config"],"exampleFix":"// before\nFieldParser.value(\"CompressionTyppe.LZ4\", CompressionType.class) // typo\n// after\nFieldParser.value(\"LZ4\", CompressionType.class)","handlingStrategy":"validation","validationCode":"boolean valid = Arrays.stream(CompressionType.values())\n    .anyMatch(e -> e.name().equals(cfgValue.trim()));\nif (!valid) throw new IllegalArgumentException(\"invalid enum value: \" + cfgValue);","typeGuard":"static <E extends Enum<E>> boolean isValidEnumValue(String s, Class<E> type) {\n    if (s == null) return false;\n    return Arrays.stream(type.getEnumConstants()).anyMatch(e -> e.name().equals(s.trim()));\n}","tryCatchPattern":"try {\n    Object v = FieldParser.value(raw, CompressionType.class);\n} catch (RuntimeException e) {\n    log.error(\"Config value '{}' is not a valid {}; valid: {}\", raw, \"CompressionType\",\n        Arrays.toString(CompressionType.values()));\n    throw e;\n}","preventionTips":["Trim and exact-match enum constant names (case-sensitive) before writing config","Validate config files against a schema listing valid enum constants at startup","Check the target Pulsar version's enum when copying config between releases","Keep enum values free of quotes/whitespace in YAML/properties files"],"tags":["configuration","enum","parsing","fieldparser"],"backgroundTag":"invalid-enum-value","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}