{"id":"8e70b6e1bacc6f46","repo":"apache/kafka","slug":"invalid-configuration-value-for-acks-acksstrin","errorCode":null,"errorMessage":"Invalid configuration value for 'acks': {acksString}","messagePattern":"Invalid configuration value for 'acks': (.+?)","errorType":"validation","errorClass":"ConfigException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/producer/ProducerConfig.java","lineNumber":709,"sourceCode":"        // In standard Kafka transactions, the broker enforces transaction.timeout.ms and aborts any\n        // transaction that isn't completed in time. With two-phase commit (2PC), an external coordinator\n        // decides when to finalize, so broker-side timeouts don't apply. Disallow using both.\n        boolean enable2PC = this.getBoolean(TRANSACTION_TWO_PHASE_COMMIT_ENABLE_CONFIG);\n        boolean userConfiguredTransactionTimeout = originalConfigs.containsKey(TRANSACTION_TIMEOUT_CONFIG);\n        if (enable2PC && userConfiguredTransactionTimeout) {\n            throw new ConfigException(\n                \"Cannot set \" + ProducerConfig.TRANSACTION_TIMEOUT_CONFIG +\n                \" when \" + ProducerConfig.TRANSACTION_TWO_PHASE_COMMIT_ENABLE_CONFIG +\n                \" is set to true. Transactions will not expire with two-phase commit enabled.\"\n            );\n        }\n    }\n\n    private static String parseAcks(String acksString) {\n        try {\n            return acksString.trim().equalsIgnoreCase(\"all\") ? \"-1\" : Short.parseShort(acksString.trim()) + \"\";\n        } catch (NumberFormatException e) {\n            throw new ConfigException(\"Invalid configuration value for 'acks': \" + acksString);\n        }\n    }\n\n    static Map<String, Object> appendSerializerToConfig(Map<String, Object> configs,\n            Serializer<?> keySerializer,\n            Serializer<?> valueSerializer) {\n        // validate serializer configuration, if the passed serializer instance is null, the user must explicitly set a valid serializer configuration value\n        Map<String, Object> newConfigs = new HashMap<>(configs);\n        if (keySerializer != null)\n            newConfigs.put(KEY_SERIALIZER_CLASS_CONFIG, keySerializer.getClass());\n        else if (newConfigs.get(KEY_SERIALIZER_CLASS_CONFIG) == null)\n            throw new ConfigException(KEY_SERIALIZER_CLASS_CONFIG, null, \"must be non-null.\");\n        if (valueSerializer != null)\n            newConfigs.put(VALUE_SERIALIZER_CLASS_CONFIG, valueSerializer.getClass());\n        else if (newConfigs.get(VALUE_SERIALIZER_CLASS_CONFIG) == null)\n            throw new ConfigException(VALUE_SERIALIZER_CLASS_CONFIG, null, \"must be non-null.\");\n        return newConfigs;\n    }","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/producer/ProducerConfig.java#L691-L727","documentation":"Thrown by ProducerConfig.parseAcks when the configured value for `acks` is neither the literal string 'all' (case-insensitive) nor a valid 16-bit signed short. parseAcks trims the input, maps 'all' to '-1', and otherwise calls Short.parseShort; any non-numeric or out-of-range input raises NumberFormatException which is converted to this ConfigException. Note the message echoes only the raw string, not which config key it came from.","triggerScenarios":"Calling `props.put(\"acks\", \"any\")`, `acks=-30000` (out of short range), `acks=true`, or any non-numeric token other than 'all'. Triggered during KafkaProducer construction via postProcessAndValidateIdotenceConfigs -> parseAcks at ProducerConfig.java:707.","commonSituations":"Misspelling 'all' as 'ALL' is fine (case-insensitive) but 'any', 'yes', 'full', or 'true' are common typos; loading acks from an environment variable or YAML where it was serialized as a non-string type; passing a Boolean instead of a String.","solutions":["Set `acks` to one of: `all`, `-1`, `0`, or `1` as a string.","If the value is supplied dynamically, validate it is one of those before constructing the producer.","Check environment-variable substitution and YAML/JSON serialization layers that may have coerced the value."],"exampleFix":"// before\nprops.put(\"acks\", \"any\");\n\n// after\nprops.put(\"acks\", \"all\");","handlingStrategy":"type-guard","validationCode":"// Normalise and validate acks BEFORE handing the config to KafkaProducer.\nstatic String normalizeAcks(Object acksRaw) {\n    String s = String.valueOf(acksRaw).trim();\n    if (s.equalsIgnoreCase(\"all\")) return \"all\";\n    try {\n        short v = Short.parseShort(s);\n        if (v < -1) throw new IllegalArgumentException(\"acks too small: \" + s);\n        return Short.toString(v);\n    } catch (NumberFormatException e) {\n        throw new IllegalArgumentException(\"Invalid acks value: \" + acksRaw);\n    }\n}\n// Caller:\ncfg.put(ProducerConfig.ACKS_CONFIG, normalizeAcks(cfg.get(ProducerConfig.ACKS_CONFIG)));","typeGuard":"// Narrow an arbitrary config value to a proven-valid acks string.\nstatic final java.util.regex.Pattern ACKS = java.util.regex.Pattern.compile(\"^(all|-1|\\\\d+)$\", java.util.regex.Pattern.CASE_INSENSITIVE);\nstatic boolean isAcksValue(Object o) {\n    if (o == null) return false;\n    String s = String.valueOf(o).trim();\n    if (!ACKS.matcher(s).matches()) return false;\n    try { Short.parseShort(s.equalsIgnoreCase(\"all\") ? \"-1\" : s); return true; }\n    catch (NumberFormatException e) { return false; }\n}\n// Use: assert isAcksValue(cfg.get(ProducerConfig.ACKS_CONFIG));","tryCatchPattern":"try {\n    producer = new KafkaProducer<>(cfg);\n} catch (ConfigException e) {\n    if (e.getMessage().contains(\"'acks'\")) {\n        cfg.put(ProducerConfig.ACKS_CONFIG, \"all\"); // safe default\n        producer = new KafkaProducer<>(cfg);\n    } else throw e;\n}","preventionTips":["Valid acks values are 'all' (==-1), 0, 1, or a positive replica count — nothing else parses.","Don't compute acks from free-form env vars without a guard; a trailing space or typo triggers this.","Centralize acks normalization so Integer/Short/String forms all converge to one canonical value."],"tags":["kafka","producer","configuration","validation"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}