{"id":"dfc38fafdff51d6b","repo":"apache/kafka","slug":"string-may-not-be-empty","errorCode":null,"errorMessage":"String may not be empty","messagePattern":"String may not be empty","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":1257,"sourceCode":"    }\n\n    public static class NonEmptyStringWithoutControlChars implements Validator {\n\n        public static NonEmptyStringWithoutControlChars nonEmptyStringWithoutControlChars() {\n            return new NonEmptyStringWithoutControlChars();\n        }\n\n        @Override\n        public void ensureValid(String name, Object value) {\n            String s = (String) value;\n\n            if (s == null) {\n                // This can happen during creation of the config object due to no default value being defined for the\n                // name configuration - a missing name parameter is caught when checking for mandatory parameters,\n                // thus we can ok a null value here\n                return;\n            } else if (s.isEmpty()) {\n                throw new ConfigException(name, value, \"String may not be empty\");\n            }\n\n            // Check name string for illegal characters\n            ArrayList<Integer> foundIllegalCharacters = new ArrayList<>();\n\n            for (int i = 0; i < s.length(); i++) {\n                if (Character.isISOControl(s.codePointAt(i))) {\n                    foundIllegalCharacters.add(s.codePointAt(i));\n                }\n            }\n\n            if (!foundIllegalCharacters.isEmpty()) {\n                throw new ConfigException(name, value, \"String may not contain control sequences but had the following ASCII chars: \" +\n                        foundIllegalCharacters.stream().map(Object::toString).collect(Collectors.joining(\", \")));\n            }\n        }\n\n        public String toString() {","sourceCodeStart":1239,"sourceCodeEnd":1275,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L1239-L1275","documentation":"Thrown by NonEmptyStringWithoutControlChars.ensureValid when the value is non-null and isEmpty(). Unlike NonEmptyString, this validator also scans for ISO control characters; the empty-string branch is checked first and emits this specific message. The validator deliberately tolerates null (returns early) because a missing value for the config is caught separately when checking mandatory parameters, so null is treated as 'not yet supplied'.","triggerScenarios":"A ConfigKey validated with NonEmptyStringWithoutControlChars.nonEmptyStringWithoutControlChars() is supplied an empty string. Most prominently used for the broker/controller 'name' (listeners/advertised.listeners naming) and similar identifier configs. Triggered during ConfigDef.parse().","commonSituations":"Identifier or name fields (listener names, topic names where this validator is reused, plugin config keys) set to an empty string via a properties file (`name=`) or programmatic empty assignment. Common in templated deployments where a placeholder was not filled.","solutions":["Provide a non-empty, control-character-free value for the named config.","If the field is optional in your workflow, omit the key rather than assigning an empty string (null is accepted).","Audit property files and env-var substitutions for empty assignments to the offending key."],"exampleFix":"// before\nprops.put(\"listener.name.internal.sasl.enabled.mechanisms\", \"\");\n\n// after\nprops.put(\"listener.name.internal.sasl.enabled.mechanisms\", \"PLAIN\");","handlingStrategy":"validation","validationCode":"// NonEmptyStringWithoutControlChars rejects empty (but tolerates null).\n// Common on 'group.id', 'client.id' style identifiers — pre-check:\nString[] nonEmptyKeys = {\"group.id\", \"client.id\", \"transactional.id\"};\nfor (String k : nonEmptyKeys) {\n    Object v = props.get(k);\n    if (v instanceof String && ((String) v).isEmpty()) {\n        throw new IllegalArgumentException(k + \" may not be empty\");\n    }\n}","typeGuard":"// Wrap in a value type that cannot be constructed empty:\nstatic final class NonEmptyStr {\n    final String value;\n    NonEmptyStr(String v) {\n        if (v == null || v.isEmpty()) throw new IllegalArgumentException(\"empty\");\n        this.value = v;\n    }\n}","tryCatchPattern":"try {\n    new KafkaConsumer<>(props);\n} catch (ConfigException ce) {\n    if (ce.getMessage().equals(\"String may not be empty\")) {\n        log.error(\"Kafka config '{}' is empty; supply a value\", ce.getName());\n        failStartup();\n    } else throw ce;\n}","preventionTips":["For identifiers like client.id / group.id, always derive from deployment metadata (pod name, host) so they're never empty.","Fail fast at startup with a clear message rather than letting Kafka reject it later.","Write a smoke test that boots the consumer with the production config file."],"tags":["config","kafka-client","validation","validator","empty-string","identifier"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}