apache/pulsar · error · RuntimeException
Invalid value '' for enum
Error message
Invalid value '' for enum
What it means
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.
Source
Thrown at pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java:113
// Lookup the suitable converter.
String converterId = from.getClass().getName() + "_" + to.getName();
Method converter = CONVERTERS.get(converterId);
if (to.isEnum()) {
// Converting string to enum
DeserializationConfig deserializationConfig =
ObjectMapperFactory.getMapper().getObjectMapper().getDeserializationConfig();
// No replacement API available in Jackson 2.x
AnnotatedClass annotatedEnum = AnnotatedClassResolver.resolve(
deserializationConfig,
deserializationConfig.getTypeFactory().constructType(to),
deserializationConfig
);
EnumResolver r = EnumResolver.constructUsingToString(deserializationConfig, annotatedEnum);
T value = (T) r.findEnum((String) from);
if (value == null) {
throw new RuntimeException("Invalid value '" + from + "' for enum " + to);
}
return value;
}
if (converter == null) {
throw new UnsupportedOperationException("Cannot convert from " + from.getClass().getName() + " to "
+ to.getName() + ". Requested converter does not exist.");
}
// Convert the value.
try {
Object val = converter.invoke(to, from);
return to.cast(val);
} catch (Exception e) {
throw new RuntimeException("Cannot convert from " + from.getClass().getName() + " to " + to.getName()
+ ". Conversion failed with " + e.getMessage(), e);
}
}View on GitHub (pinned to 820761864e)
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
Example fix
// before
FieldParser.value("CompressionTyppe.LZ4", CompressionType.class) // typo
// after
FieldParser.value("LZ4", CompressionType.class) Defensive patterns
Strategy: validation
Validate before calling
boolean valid = Arrays.stream(CompressionType.values())
.anyMatch(e -> e.name().equals(cfgValue.trim()));
if (!valid) throw new IllegalArgumentException("invalid enum value: " + cfgValue); Type guard
static <E extends Enum<E>> boolean isValidEnumValue(String s, Class<E> type) {
if (s == null) return false;
return Arrays.stream(type.getEnumConstants()).anyMatch(e -> e.name().equals(s.trim()));
} Try / catch
try {
Object v = FieldParser.value(raw, CompressionType.class);
} catch (RuntimeException e) {
log.error("Config value '{}' is not a valid {}; valid: {}", raw, "CompressionType",
Arrays.toString(CompressionType.values()));
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- --offloadedReadPriority parameter must be one of ${allowed}
- Malformed configuration file
- Unsupported token endpoint auth method: ${value}
- Invalid topic domain: '${value}'
- Unrecognized auto_failover_policy: ${policyType}
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/36018f34e8a715ae.
Report an issue: GitHub.