{"id":"d26fee49a73e5e93","repo":"apache/kafka","slug":"string-must-be-one-of-case-insensitive-string-j","errorCode":null,"errorMessage":"String must be one of (case insensitive): String.join(\", \", validStrings)","messagePattern":"String must be one of \\(case insensitive\\): String\\.join\\(\", \", validStrings\\)","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":1144,"sourceCode":"    public static class CaseInsensitiveValidString implements Validator {\n\n        final Set<String> validStrings;\n\n        private CaseInsensitiveValidString(List<String> validStrings) {\n            this.validStrings = validStrings.stream()\n                .map(s -> s.toUpperCase(Locale.ROOT))\n                .collect(Collectors.toSet());\n        }\n\n        public static CaseInsensitiveValidString in(String... validStrings) {\n            return new CaseInsensitiveValidString(Arrays.asList(validStrings));\n        }\n\n        @Override\n        public void ensureValid(String name, Object o) {\n            String s = (String) o;\n            if (s == null || !validStrings.contains(s.toUpperCase(Locale.ROOT))) {\n                throw new ConfigException(name, o, \"String must be one of (case insensitive): \" + String.join(\", \", validStrings));\n            }\n        }\n\n        public String toString() {\n            return \"(case insensitive) [\" + String.join(\", \", validStrings) + \"]\";\n        }\n    }\n\n    public static class NonNullValidator implements Validator {\n        @Override\n        public void ensureValid(String name, Object value) {\n            if (value == null) {\n                // Pass in the string null to avoid the spotbugs warning\n                throw new ConfigException(name, \"null\", \"entry must be non null\");\n            }\n        }\n\n        public String toString() {","sourceCodeStart":1126,"sourceCodeEnd":1162,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L1126-L1162","documentation":"Thrown by CaseInsensitiveValidString.ensureValid when the supplied value is null OR its uppercase form is not in the validator's pre-uppercased validStrings set. Unlike ValidString this validator normalizes case via toUpperCase(Locale.ROOT) on both sides, so 'ssl', 'Ssl', 'SSL' are equivalent; the message still lists the (uppercased) permitted values for clarity.","triggerScenarios":"A ConfigKey validated with CaseInsensitiveValidString.in(\"SSL\",\"PLAINTEXT\",\"SASL_PLAINTEXT\",\"SASL_SSL\") receives a value whose uppercase form is none of these, or receives null. Triggered during ConfigDef.parse() when ensureValid is invoked.","commonSituations":"Subtle typos that case normalization cannot fix (\"SSl\" still matches \"SSL\", but \"SSSL\" does not), whitespace or hidden characters in the value, or genuinely unsupported protocol names. The null branch fires when a no-default optional config is omitted in certain code paths.","solutions":["Use one of the values listed in the message (case does not matter, but spelling and punctuation must match: underscores, digits).","If the value comes from an env var or file, trim it and confirm there are no trailing whitespace or hidden characters.","If you hit the null branch, provide an explicit default for the ConfigKey or always set the property."],"exampleFix":"// before\nprops.put(\"security.protocol\", \"sssl\");  // typo\n\n// after\nprops.put(\"security.protocol\", \"ssl\");","handlingStrategy":"validation","validationCode":"// Case-insensitive membership check mirroring CaseInsensitiveValidString:\nSet<String> allowedUpper = allowed.stream().map(s -> s.toUpperCase(Locale.ROOT)).collect(Collectors.toSet());\nString val = (String) configs.get(key);\nif (val == null || !allowedUpper.contains(val.toUpperCase(Locale.ROOT))) {\n    throw new IllegalArgumentException(key + \" must be one of (case insensitive) \" + allowed);\n}","typeGuard":"null","tryCatchPattern":"try {\n    def.parse(props);\n} catch (ConfigException ce) {\n    if (ce.getMessage().contains(\"case insensitive)\")) {\n        // Normalize and retry with the canonical-cased value\n        String canonical = findCanonical(ce.value().toString().toUpperCase(Locale.ROOT));\n        props.put(ce.getName(), canonical);\n    } else throw ce;\n}","preventionTips":["Always store config strings in the canonical case shown in Kafka docs to avoid mismatches.","When accepting user input, uppercase before comparing against the allow-list.","Document the case-insensitive contract to operators so they don't try to 'fix' a working value by changing case."],"tags":["config","kafka-client","validation","validator","enum","case-insensitive"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}