{"id":"392b1c0fc0f3fbf6","repo":"apache/kafka","slug":"invalid-acknowledgement-mode","errorCode":null,"errorMessage":"Invalid acknowledgement mode: {}","messagePattern":"Invalid acknowledgement mode: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareAcknowledgementMode.java","lineNumber":63,"sourceCode":"    }\n\n    /**\n     * Returns the ShareAcknowledgementMode from the given string.\n     */\n    public static ShareAcknowledgementMode fromString(String acknowledgementMode) {\n        if (acknowledgementMode == null) {\n            throw new IllegalArgumentException(\"Acknowledgement mode is null\");\n        }\n\n        if (Arrays.asList(Utils.enumOptions(AcknowledgementMode.class)).contains(acknowledgementMode)) {\n            AcknowledgementMode mode = AcknowledgementMode.valueOf(acknowledgementMode.toUpperCase(Locale.ROOT));\n            switch (mode) {\n                case IMPLICIT:\n                    return IMPLICIT;\n                case EXPLICIT:\n                    return EXPLICIT;\n                default:\n                    throw new IllegalArgumentException(\"Invalid acknowledgement mode: \" + acknowledgementMode);\n            }\n        } else {\n            throw new IllegalArgumentException(\"Invalid acknowledgement mode: \" + acknowledgementMode);\n        }\n    }\n\n    /**\n     * Returns the name of the acknowledgement mode.\n     */\n    public String name() {\n        return acknowledgementMode.toString();\n    }\n\n    @Override\n    public boolean equals(Object o) {\n        if (this == o) return true;\n        if (o == null || getClass() != o.getClass()) return false;\n        ShareAcknowledgementMode that = (ShareAcknowledgementMode) o;","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareAcknowledgementMode.java#L45-L81","documentation":"Thrown by the default branch of the switch inside ShareAcknowledgementMode.fromString(String) after valueOf() already succeeded. In practice this branch is unreachable because the only enum constants are IMPLICIT and EXPLICIT, both of which are cased above; the message exists as a defensive guard against future enum constants being added without updating the switch. Hitting it almost always indicates the enum was extended without updating this method.","triggerScenarios":"Adding a new AcknowledgementMode constant without adding a case to the switch in fromString(); reflective or deserialization tricks that yield an enum value outside the cased set.","commonSituations":"Contributors extending AcknowledgementMode during share-group protocol development and forgetting to update fromString(); running against a patched Kafka JAR where the enum and the switch are out of sync.","solutions":["If you added a new AcknowledgementMode constant, add a matching case to the switch in ShareAcknowledgementMode.fromString().","Ensure the client JAR on the classpath matches the source (no partial builds / mixed versions).","Prefer replacing the switch with a direct return of the resolved mode so future constants are handled automatically."],"exampleFix":"// before\nswitch (mode) {\n    case IMPLICIT: return IMPLICIT;\n    case EXPLICIT: return EXPLICIT;\n    default: throw new IllegalArgumentException(\"Invalid acknowledgement mode: \" + s);\n}\n\n// after\n// once AcknowledgementMode has more constants, either add cases or drop the switch:\nreturn new ShareAcknowledgementMode(mode);","handlingStrategy":"validation","validationCode":"// Whitelist accepted mode strings (case-insensitive) before calling fromString.\njava.util.Set<String> ALLOWED = java.util.Set.of(\"implicit\", \"explicit\");\nString normalized = mode == null ? null : mode.toLowerCase(java.util.Locale.ROOT);\nif (normalized == null || !ALLOWED.contains(normalized)) {\n    throw new IllegalArgumentException(\n        \"Invalid acknowledgement mode: \" + mode + \"; must be one of \" + ALLOWED);\n}\nShareAcknowledgementMode.fromString(normalized);","typeGuard":"java.util.function.Function<String, ShareAcknowledgementMode> parseMode = s -> {\n    String n = s == null ? null : s.trim().toLowerCase(java.util.Locale.ROOT);\n    switch (n) {\n        case \"implicit\": return ShareAcknowledgementMode.IMPLICIT;\n        case \"explicit\": return ShareAcknowledgementMode.EXPLICIT;\n        default:\n            throw new IllegalArgumentException(\n                \"Invalid acknowledgement mode: \" + s + \"; expected 'implicit' or 'explicit'\");\n    }\n};","tryCatchPattern":"try {\n    ShareAcknowledgementMode.fromString(mode);\n} catch (IllegalArgumentException ex) {\n    // unknown mode; surface a clear validation error to the user/config source\n    throw new IllegalArgumentException(\n        \"share acknowledgement mode '\" + mode + \"' is not valid; use 'implicit' or 'explicit'\", ex);\n}","preventionTips":["Constrain mode input to a documented enum set at the trust boundary (UI, CLI, config file).","Normalize case before comparison so 'IMPLICIT' and 'implicit' both work.","Log the offending value verbatim in the error message to aid debugging."],"tags":["share-consumer","config","unreachable","enum"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}