{"record":{"id":"6ac640fc8ba2c253","repo":"apache/pulsar","slug":"field-name-is-not-an-accepted-value-value-o","errorCode":null,"errorMessage":"Field ${name} is not an accepted value. Value: ${o} Accepted values: ${acceptedValues}","messagePattern":"Field (.+?) is not an accepted value\\. Value: (.+?) Accepted values: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ValidatorImpls.java","lineNumber":297,"sourceCode":"\n        public StringValidator(Map<String, Object> params) {\n\n            this.acceptedValues =\n                    new HashSet<String>(Arrays.asList((String[]) params.get(\n                            ConfigValidationAnnotations.ValidatorParams.ACCEPTED_VALUES)));\n\n            if (this.acceptedValues.isEmpty()\n                    || (this.acceptedValues.size() == 1 && this.acceptedValues.contains(\"\"))) {\n                this.acceptedValues = null;\n            }\n        }\n\n        @Override\n        public void validateField(String name, Object o) {\n            SimpleTypeValidator.validateField(name, String.class, o);\n            if (this.acceptedValues != null) {\n                if (!this.acceptedValues.contains((String) o)) {\n                    throw new IllegalArgumentException(\n                            \"Field \" + name + \" is not an accepted value. Value: \" + o\n                                    + \" Accepted values: \" + this.acceptedValues);\n                }\n            }\n        }\n    }\n\n    /**\n     * Validates each entry in a list against a list of custom Validators. Each validator in the\n     * list of validators must inherit or be an instance of Validator class\n     */\n    public static class ListEntryCustomValidator extends Validator {\n\n        private Class<?>[] entryValidators;\n\n        public ListEntryCustomValidator(Map<String, Object> params) {\n            this.entryValidators = (Class<?>[]) params.get(\n                    ConfigValidationAnnotations.ValidatorParams.ENTRY_VALIDATOR_CLASSES);","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-config-validation/src/main/java/org/apache/pulsar/config/validation/ValidatorImpls.java#L279-L315","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the field to exactly one of the accepted values listed in the error message.","Match casing and trim whitespace around the value in your config file.","Check the version's documentation — accepted value sets can change between releases.","Pre-validate the value against the same accepted set before submitting config."],"exampleFix":"// before (YAML)\ncompressionType: zstd1  // not an accepted value\n// after\ncompressionType: ZSTD","handlingStrategy":"validation","validationCode":"Set<String> accepted = Set.of(\"ZSTD\", \"LZ4\", \"SNAPPY\");\nString value = configValue.trim();\nif (!accepted.contains(value)) {\n    throw new IllegalArgumentException(value + \" not in \" + accepted);\n}","typeGuard":null,"tryCatchPattern":"try {\n    validator.validateField(\"compressionType\", value);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Invalid value '{}', falling back to default\", value, e);\n    config.setCompressionType(DEFAULT_COMPRESSION);\n}","preventionTips":["Always trim config strings before validation to catch whitespace issues.","Match the exact casing shown in the error message's accepted list.","Re-check accepted values after library upgrades — the set can change.","Use IDE/JSON-schema enums in config files to get autocomplete and early errors."],"tags":["java","config-validation","enum-values","illegal-argument"],"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-14T05:17:10.506Z"}