{"id":"a93927278b6884dd","repo":"apache/kafka","slug":"enable-auto-commit-cannot-be-set-to-true-when-defa","errorCode":null,"errorMessage":"enable.auto.commit cannot be set to true when default group id (null) is used.","messagePattern":"enable\\.auto\\.commit cannot be set to true when default group id \\(null\\) is used\\.","errorType":"exception","errorClass":"InvalidConfigurationException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java","lineNumber":814,"sourceCode":"            newConfigs.put(KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializer.getClass());\n        else if (newConfigs.get(KEY_DESERIALIZER_CLASS_CONFIG) == null)\n            throw new ConfigException(KEY_DESERIALIZER_CLASS_CONFIG, null, \"must be non-null.\");\n        if (valueDeserializer != null)\n            newConfigs.put(VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializer.getClass());\n        else if (newConfigs.get(VALUE_DESERIALIZER_CLASS_CONFIG) == null)\n            throw new ConfigException(VALUE_DESERIALIZER_CLASS_CONFIG, null, \"must be non-null.\");\n        return newConfigs;\n    }\n\n    private void maybeOverrideEnableAutoCommit(Map<String, Object> configs) {\n        Optional<String> groupId = Optional.ofNullable(getString(CommonClientConfigs.GROUP_ID_CONFIG));\n        Map<String, Object> originals = originals();\n        boolean enableAutoCommit = originals.containsKey(ENABLE_AUTO_COMMIT_CONFIG) ? getBoolean(ENABLE_AUTO_COMMIT_CONFIG) : false;\n        if (groupId.isEmpty()) { // overwrite in case of default group id where the config is not explicitly provided\n            if (!originals.containsKey(ENABLE_AUTO_COMMIT_CONFIG)) {\n                configs.put(ENABLE_AUTO_COMMIT_CONFIG, false);\n            } else if (enableAutoCommit) {\n                throw new InvalidConfigurationException(ENABLE_AUTO_COMMIT_CONFIG + \" cannot be set to true when default group id (null) is used.\");\n            }\n        }\n    }\n\n    protected void checkUnsupportedConfigsPostProcess() {\n        String groupProtocol = getString(GROUP_PROTOCOL_CONFIG);\n        if (GroupProtocol.CLASSIC.name().equalsIgnoreCase(groupProtocol)) {\n            checkUnsupportedConfigsPostProcess(GroupProtocol.CLASSIC, CLASSIC_PROTOCOL_UNSUPPORTED_CONFIGS);\n        } else if (GroupProtocol.CONSUMER.name().equalsIgnoreCase(groupProtocol)) {\n            checkUnsupportedConfigsPostProcess(GroupProtocol.CONSUMER, CONSUMER_PROTOCOL_UNSUPPORTED_CONFIGS);\n        }\n    }\n\n    private void checkUnsupportedConfigsPostProcess(GroupProtocol groupProtocol, List<String> unsupportedConfigs) {\n        if (getString(GROUP_PROTOCOL_CONFIG).equalsIgnoreCase(groupProtocol.name())) {\n            List<String> invalidConfigs = new ArrayList<>();\n            unsupportedConfigs.forEach(configName -> {\n                Object config = originals().get(configName);","sourceCodeStart":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java#L796-L832","documentation":"Thrown by ConsumerConfig.maybeOverrideEnableAutoCommit when group.id is unset (default/null) AND the user has explicitly set enable.auto.commit=true. Auto-commit only makes sense for a stable, identified group; with a null group the broker assigns a transient id, so committing offsets is meaningless and the client rejects the combination. It is an InvalidConfigurationException.","triggerScenarios":"Constructing a KafkaConsumer whose properties set enable.auto.commit=true (or enable.auto.commit explicitly) but omit group.id (or set it to null/empty). The check only fires when ENABLE_AUTO_COMMIT_CONFIG is present AND truthy while GROUP_ID_CONFIG is absent.","commonSituations":"Standalone/no-group consumer (e.g. assign-mode consumer reading a topic without joining a group) that copy-pastes a group consumer's properties including enable.auto.commit=true; config templating that defaults enable.auto.commit=true but leaves group.id blank for non-grouped consumers; using the same Properties object across a group consumer and a plain assign() consumer.","solutions":["Set group.id to a stable non-empty value if you actually want auto-commit semantics.","For assign()-style consumers without a group, set enable.auto.commit=false (or remove the property) and commit offsets manually when needed.","Remove enable.auto.commit from shared config templates that are reused for groupless consumers."],"exampleFix":"// before\nprops.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, \"true\");\n// group.id omitted\nnew KafkaConsumer<>(props); // throws\n\n// after (option A: real group consumer)\nprops.put(ConsumerConfig.GROUP_ID_CONFIG, \"order-processor\");\n\n// after (option B: assign-style, no group)\nprops.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, \"false\");","handlingStrategy":"validation","validationCode":"// If you want enable.auto.commit=true you must supply a non-null group.id:\nboolean enableAutoCommit = Boolean.TRUE.equals(props.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG));\nString groupId = (String) props.get(ConsumerConfig.GROUP_ID_CONFIG);\nif (enableAutoCommit && (groupId == null || groupId.isEmpty())) {\n    throw new org.apache.kafka.common.config.ConfigException(\n        ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, true,\n        \"cannot be true when group.id is null/empty\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    new KafkaConsumer<>(props);\n} catch (org.apache.kafka.common.config.ConfigException e) {\n    if (e.getMessage().contains(\"enable.auto commit cannot be set to true\")) {\n        props.put(ConsumerConfig.GROUP_ID_CONFIG, \"my-app-group\");\n        new KafkaConsumer<>(props);\n    } else throw e;\n}","preventionTips":["Auto-commit only makes sense as part of a consumer group; without group.id the consumer uses no coordinator and auto-commit is meaningless.","Either set group.id or set enable.auto.commit=false and commit offsets manually via commitSync/commitAsync.","For non-group (subscription-free) assignment patterns, prefer manual offset commits."],"tags":["consumer","configuration","auto-commit","group-id","startup","java"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}