apache/kafka · error · InvalidConfigurationException

enable.auto.commit cannot be set to true when default group

Error message

enable.auto.commit cannot be set to true when default group id (null) is used.

What it means

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.

Source

Thrown at clients/src/main/java/org/apache/kafka/clients/consumer/ConsumerConfig.java:814

            newConfigs.put(KEY_DESERIALIZER_CLASS_CONFIG, keyDeserializer.getClass());
        else if (newConfigs.get(KEY_DESERIALIZER_CLASS_CONFIG) == null)
            throw new ConfigException(KEY_DESERIALIZER_CLASS_CONFIG, null, "must be non-null.");
        if (valueDeserializer != null)
            newConfigs.put(VALUE_DESERIALIZER_CLASS_CONFIG, valueDeserializer.getClass());
        else if (newConfigs.get(VALUE_DESERIALIZER_CLASS_CONFIG) == null)
            throw new ConfigException(VALUE_DESERIALIZER_CLASS_CONFIG, null, "must be non-null.");
        return newConfigs;
    }

    private void maybeOverrideEnableAutoCommit(Map<String, Object> configs) {
        Optional<String> groupId = Optional.ofNullable(getString(CommonClientConfigs.GROUP_ID_CONFIG));
        Map<String, Object> originals = originals();
        boolean enableAutoCommit = originals.containsKey(ENABLE_AUTO_COMMIT_CONFIG) ? getBoolean(ENABLE_AUTO_COMMIT_CONFIG) : false;
        if (groupId.isEmpty()) { // overwrite in case of default group id where the config is not explicitly provided
            if (!originals.containsKey(ENABLE_AUTO_COMMIT_CONFIG)) {
                configs.put(ENABLE_AUTO_COMMIT_CONFIG, false);
            } else if (enableAutoCommit) {
                throw new InvalidConfigurationException(ENABLE_AUTO_COMMIT_CONFIG + " cannot be set to true when default group id (null) is used.");
            }
        }
    }

    protected void checkUnsupportedConfigsPostProcess() {
        String groupProtocol = getString(GROUP_PROTOCOL_CONFIG);
        if (GroupProtocol.CLASSIC.name().equalsIgnoreCase(groupProtocol)) {
            checkUnsupportedConfigsPostProcess(GroupProtocol.CLASSIC, CLASSIC_PROTOCOL_UNSUPPORTED_CONFIGS);
        } else if (GroupProtocol.CONSUMER.name().equalsIgnoreCase(groupProtocol)) {
            checkUnsupportedConfigsPostProcess(GroupProtocol.CONSUMER, CONSUMER_PROTOCOL_UNSUPPORTED_CONFIGS);
        }
    }

    private void checkUnsupportedConfigsPostProcess(GroupProtocol groupProtocol, List<String> unsupportedConfigs) {
        if (getString(GROUP_PROTOCOL_CONFIG).equalsIgnoreCase(groupProtocol.name())) {
            List<String> invalidConfigs = new ArrayList<>();
            unsupportedConfigs.forEach(configName -> {
                Object config = originals().get(configName);

View on GitHub (pinned to c31c9215e1)

Solutions

  1. Set group.id to a stable non-empty value if you actually want auto-commit semantics.
  2. For assign()-style consumers without a group, set enable.auto.commit=false (or remove the property) and commit offsets manually when needed.
  3. Remove enable.auto.commit from shared config templates that are reused for groupless consumers.

Example fix

// before
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true");
// group.id omitted
new KafkaConsumer<>(props); // throws

// after (option A: real group consumer)
props.put(ConsumerConfig.GROUP_ID_CONFIG, "order-processor");

// after (option B: assign-style, no group)
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
Defensive patterns

Strategy: validation

Validate before calling

// If you want enable.auto.commit=true you must supply a non-null group.id:
boolean enableAutoCommit = Boolean.TRUE.equals(props.get(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG));
String groupId = (String) props.get(ConsumerConfig.GROUP_ID_CONFIG);
if (enableAutoCommit && (groupId == null || groupId.isEmpty())) {
    throw new org.apache.kafka.common.config.ConfigException(
        ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, true,
        "cannot be true when group.id is null/empty");
}

Try / catch

try {
    new KafkaConsumer<>(props);
} catch (org.apache.kafka.common.config.ConfigException e) {
    if (e.getMessage().contains("enable.auto commit cannot be set to true")) {
        props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-app-group");
        new KafkaConsumer<>(props);
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/a93927278b6884dd.json. Report an issue: GitHub.