{"record":{"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":"validation","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/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java#L796-L832","documentation":"Thrown by ConsumerConfig.maybeOverrideEnableAutoCommit when group.id is null/empty (the default group id) but enable.auto.commit is explicitly set to true. Auto-commit only makes sense in the context of a group, so the consumer refuses to start in a contradictory state. Thrown as InvalidConfigurationException (a subclass of ConfigException).","triggerScenarios":"Constructing a KafkaConsumer whose Properties omit group.id (or set it to empty) AND set enable.auto.commit=true. Common in standalone/assignment consumers that don't need a group but accidentally inherit auto-commit config.","commonSituations":"Using assign() patterns without a group id but copying a config template that has enable.auto.commit=true; transitioning from group consumption to standalone and forgetting to flip auto-commit off; defaulting group.id to empty in a multi-tenant loader.","solutions":["If you need a group, set group.id to a non-empty value.","If you don't use a group, set enable.auto.commit=false and commit manually (or use assign/seek patterns).","Remove enable.auto.commit from the config so the client applies its own default when a group id is present."],"exampleFix":"// before\nprops.put(\"enable.auto.commit\", \"true\");\n// no group.id set\nnew KafkaConsumer<>(props);\n\n// after\nprops.put(\"group.id\", \"order-processor\");\nprops.put(\"enable.auto.commit\", \"true\");\nnew KafkaConsumer<>(props);\n// OR, for standalone assignment:\nprops.put(\"enable.auto.commit\", \"false\");","handlingStrategy":"validation","validationCode":"String groupId = (String) configs.get(ConsumerConfig.GROUP_ID_CONFIG);\nboolean autoCommit = Boolean.parseBoolean(String.valueOf(configs.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG)));\nif ((groupId == null || groupId.isEmpty()) && autoCommit) {\n    throw new ConfigException(\"enable.auto.commit=true requires a non-empty group.id\");\n}","typeGuard":"static boolean autoCommitConsistent(Map<String,Object> c) {\n    String g = String.valueOf(c.get(ConsumerConfig.GROUP_ID_CONFIG));\n    boolean ac = Boolean.parseBoolean(String.valueOf(c.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG)));\n    return !(g.isEmpty() && ac);\n}","tryCatchPattern":"try {\n    consumer = new KafkaConsumer<>(props);\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"enable.auto.commit\")) {\n        props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);\n        consumer = new KafkaConsumer<>(props);\n    } else throw e;\n}","preventionTips":["Set group.id explicitly in every consumer config.","For assign()-based standalone consumers, always set enable.auto.commit=false.","LINT consumer configs in CI to catch the empty-group/auto-commit-true combination."],"tags":["consumer","config","auto-commit","group-id","validation"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}