apache/pulsar · error · IllegalArgumentException

Field ${name} is not an accepted value. Value: ${o} Accepted

Error message

Field ${name} is not an accepted value. Value: ${o} Accepted values: ${acceptedValues}

What it means

Thrown by an enumerated-values string validator. After confirming the value is a String, it checks membership in the acceptedValues set supplied when the validator was created; a value outside that set fails validation. This enforces a closed vocabulary for config fields.

Source

Thrown at pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ValidatorImpls.java:297

        public StringValidator(Map<String, Object> params) {

            this.acceptedValues =
                    new HashSet<String>(Arrays.asList((String[]) params.get(
                            ConfigValidationAnnotations.ValidatorParams.ACCEPTED_VALUES)));

            if (this.acceptedValues.isEmpty()
                    || (this.acceptedValues.size() == 1 && this.acceptedValues.contains(""))) {
                this.acceptedValues = null;
            }
        }

        @Override
        public void validateField(String name, Object o) {
            SimpleTypeValidator.validateField(name, String.class, o);
            if (this.acceptedValues != null) {
                if (!this.acceptedValues.contains((String) o)) {
                    throw new IllegalArgumentException(
                            "Field " + name + " is not an accepted value. Value: " + o
                                    + " Accepted values: " + this.acceptedValues);
                }
            }
        }
    }

    /**
     * Validates each entry in a list against a list of custom Validators. Each validator in the
     * list of validators must inherit or be an instance of Validator class
     */
    public static class ListEntryCustomValidator extends Validator {

        private Class<?>[] entryValidators;

        public ListEntryCustomValidator(Map<String, Object> params) {
            this.entryValidators = (Class<?>[]) params.get(
                    ConfigValidationAnnotations.ValidatorParams.ENTRY_VALIDATOR_CLASSES);

View on GitHub (pinned to 820761864e)

Solutions

  1. Set the field to exactly one of the accepted values listed in the error message.
  2. Match casing and trim whitespace around the value in your config file.
  3. Check the version's documentation — accepted value sets can change between releases.
  4. Pre-validate the value against the same accepted set before submitting config.

Example fix

// before (YAML)
compressionType: zstd1  // not an accepted value
// after
compressionType: ZSTD
Defensive patterns

Strategy: validation

Validate before calling

Set<String> accepted = Set.of("ZSTD", "LZ4", "SNAPPY");
String value = configValue.trim();
if (!accepted.contains(value)) {
    throw new IllegalArgumentException(value + " not in " + accepted);
}

Try / catch

try {
    validator.validateField("compressionType", value);
} catch (IllegalArgumentException e) {
    log.warn("Invalid value '{}', falling back to default", value, e);
    config.setCompressionType(DEFAULT_COMPRESSION);
}

Prevention

When it happens

Trigger: A config field with a fixed list of legal values (e.g. "Consistent", "RoundRobin") receives any other string, including null-like empty strings, different casing, or trailing whitespace that misses the Set.contains check.

Common situations: Casing mismatch ("consensus" vs "Consensus"); config copied from docs of an older version where the value existed; locale-specific or synonym spelling; whitespace from YAML/properties editing.

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


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/6ac640fc8ba2c253. Report an issue: GitHub.