{"id":"496a4f2527b998c7","repo":"apache/kafka","slug":"missing-required-configuration-key-name-which-ha","errorCode":null,"errorMessage":"Missing required configuration \"key.name\" which has no default value.","messagePattern":"Missing required configuration \"key\\.name\" which has no default value\\.","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java","lineNumber":539,"sourceCode":"        List<String> undefinedConfigKeys = undefinedDependentConfigs();\n        if (!undefinedConfigKeys.isEmpty()) {\n            String joined = undefinedConfigKeys.stream().map(String::toString).collect(Collectors.joining(\",\"));\n            throw new ConfigException(\"Some configurations in are referred in the dependents, but not defined: \" + joined);\n        }\n        // parse all known keys\n        Map<String, Object> values = new HashMap<>();\n        for (ConfigKey key : configKeys.values())\n            values.put(key.name, parseValue(key, props.get(key.name), props.containsKey(key.name)));\n        return values;\n    }\n\n    Object parseValue(ConfigKey key, Object value, boolean isSet) {\n        Object parsedValue;\n        if (isSet) {\n            parsedValue = parseType(key.name, value, key.type);\n        // props map doesn't contain setting, the key is required because no default value specified - its an error\n        } else if (NO_DEFAULT_VALUE.equals(key.defaultValue)) {\n            throw new ConfigException(\"Missing required configuration \\\"\" + key.name + \"\\\" which has no default value.\");\n        } else {\n            // otherwise assign setting its default value\n            parsedValue = key.defaultValue;\n        }\n        if (key.validator instanceof ValidList && parsedValue instanceof List) {\n            List<?> originalListValue = (List<?>) parsedValue;\n            parsedValue = originalListValue.stream().distinct().collect(Collectors.toList());\n            if (originalListValue.size() != ((List<?>) parsedValue).size()) {\n                LOGGER.warn(\"Configuration key \\\"{}\\\" contains duplicate values. Duplicates will be removed. The original value \" +\n                        \"is: {}, the updated value is: {}\", key.name, originalListValue, parsedValue);\n            }\n        }\n        if (key.validator != null) {\n            key.validator.ensureValid(key.name, parsedValue);\n        }\n        return parsedValue;\n    }\n","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java#L521-L557","documentation":"Thrown by ConfigDef.parseValue when a ConfigKey has defaultValue == NO_DEFAULT_VALUE (the sentinel at ConfigDef.java:93) and the supplied properties map does not contain that key. Such keys are required: with no default and no user value there is nothing valid to assign, so parsing aborts with a ConfigException naming the missing key.","triggerScenarios":"Constructing a Kafka client (KafkaProducer, KafkaConsumer, KafkaAdminClient, Connect worker, KafkaStreams) without supplying a required option such as bootstrap.servers, schema.registry.url (in Confluent stack), group.id for a consumer using group-based assignors, or a connector-specific required property; passing a Properties/Map that omits a key whose ConfigDef entry used the NO_DEFAULT_VALUE default.","commonSituations":"New producer/consumer that forgot bootstrap.servers; consumer without group.id; Connect connector config missing connector-specific required fields (e.g. topics for a source connector); typo in the property name so the supplied value is ignored; environment variable expansion that produced an empty value and the empty key was not put in the map; cluster deployment where required secrets were not injected.","solutions":["Read the exception message for the exact key name, then add that key with a non-empty value to the Properties/Map passed to the client or connector constructor.","Double-check the spelling and case of the key against the official ConfigDef (e.g. bootstrap.servers, not bootstrap.server).","If constructing programmatically, ensure the value is actually inserted into the map (a null value still satisfies containsKey but may fail later validation; the key must be present).","If the property is supplied via env var / file / Vault, verify the substitution actually produced a value before constructing the client.","If the key is optional in your use case, give the ConfigDef entry a real default value instead of NO_DEFAULT_VALUE when you own the schema."],"exampleFix":"// before\nProperties props = new Properties();\nprops.put(\"client.id\", \"my-app\");\nnew KafkaProducer<>(props); // throws: Missing required configuration \"bootstrap.servers\"\n\n// after\nProperties props = new Properties();\nprops.put(\"bootstrap.servers\", \"localhost:9092\");\nprops.put(\"client.id\", \"my-app\");\nnew KafkaProducer<>(props);","handlingStrategy":"validation","validationCode":"// Required Kafka client keys - check presence & non-empty BEFORE constructing the client.\nString[] required = { \"bootstrap.servers\", \"key.serializer\", \"value.serializer\" }; // adjust per client\nfor (String k : required) {\n    String v = props.getProperty(k);\n    if (v == null || v.trim().isEmpty()) {\n        throw new IllegalArgumentException(\"Missing required Kafka config '\" + k + \"'. Provide it in properties/env/file.\");\n    }\n}\n// For a custom ConfigDef, derive the list dynamically:\n// configDef.configKeys().values().stream()\n//     .filter(k -> k.defaultValue == ConfigDef.NO_DEFAULT_VALUE)\n//     .map(k -> k.name).forEach(k -> assertSupplied(props, k));","typeGuard":null,"tryCatchPattern":"try {\n    return new KafkaProducer<>(props);\n} catch (ConfigException e) {\n    if (e.getMessage().startsWith(\"Missing required configuration\")) {\n        // Surface a clearer message and a stable exit code; do NOT silently default.\n        throw new IllegalArgumentException(\"Startup blocked - \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Centralize the set of required keys in one constants class and validate against it on application startup.","Load configuration from a typed source (env vars / validated config file) and fail fast before any client is constructed.","Never rely on 'no default' configs having a value at runtime - treat their absence as a build/deploy defect.","Log the full list of resolved required keys at INFO on boot so missing ones are obvious in logs."],"tags":["config","required","missing-property","kafka-client"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}