{"id":"162649a37e4488a3","repo":"apache/kafka","slug":"acknowledgement-mode-is-null","errorCode":null,"errorMessage":"Acknowledgement mode is null","messagePattern":"Acknowledgement mode is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareAcknowledgementMode.java","lineNumber":52,"sourceCode":"            return super.toString().toLowerCase(Locale.ROOT);\n        }\n    }\n\n    private final AcknowledgementMode acknowledgementMode;\n\n    public static final ShareAcknowledgementMode IMPLICIT = new ShareAcknowledgementMode(AcknowledgementMode.IMPLICIT);\n    public static final ShareAcknowledgementMode EXPLICIT = new ShareAcknowledgementMode(AcknowledgementMode.EXPLICIT);\n\n    private ShareAcknowledgementMode(AcknowledgementMode acknowledgementMode) {\n        this.acknowledgementMode = acknowledgementMode;\n    }\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    /**","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareAcknowledgementMode.java#L34-L70","documentation":"Thrown by ShareAcknowledgementMode.fromString(String) when the supplied acknowledgement-mode string is null. The share consumer needs a non-null mode string to resolve it to either IMPLICIT or EXPLICIT; null indicates the caller (typically the config layer) failed to supply a value at all. This is a programmer/config error, not a broker-side condition.","triggerScenarios":"Calling ShareAcknowledgementMode.fromString(null) directly; the config validator invoking fromString() on a property whose value resolved to null; a Map.get() returning null that was passed straight through.","commonSituations":"Omitting the share.acknowledgement.mode property while the share consumer requires it; setting the property to a placeholder (e.g. ${ENV}) that resolved to null; programmatic configs built from a Map that did not contain the key.","solutions":["Set share.acknowledgement.mode explicitly to either \"implicit\" or \"explicit\" in consumer config.","If constructing configs programmatically, default the value before passing it in (e.g. props.getOrDefault(\"share.acknowledgement.mode\", \"implicit\")).","Null-check the resolved config value at the boundary and fail with a clearer message before it reaches fromString()."],"exampleFix":"// before\nString mode = (String) props.get(\"share.acknowledgement.mode\");\nShareAcknowledgementMode.fromString(mode); // throws if key absent\n\n// after\nString mode = (String) props.getOrDefault(\"share.acknowledgement.mode\", \"implicit\");\nShareAcknowledgementMode.fromString(mode);","handlingStrategy":"validation","validationCode":"// Validate the acknowledgement mode string before calling fromString.\nString mode = /* user/config supplied */ ;\nif (mode == null) {\n    throw new IllegalArgumentException(\n        \"share acknowledgement mode must not be null; expected 'implicit' or 'explicit'\");\n}\nShareAcknowledgementMode.fromString(mode);","typeGuard":"java.util.function.Function<String, ShareAcknowledgementMode> safeFromString = s -> {\n    if (s == null) {\n        throw new IllegalArgumentException(\n            \"Acknowledgement mode is null; expected 'implicit' or 'explicit'\");\n    }\n    return ShareAcknowledgementMode.fromString(s);\n};","tryCatchPattern":"try {\n    ShareAcknowledgementMode.fromString(mode);\n} catch (IllegalArgumentException ex) {\n    // null or unknown mode; default or prompt the user for a valid value\n    ShareAcknowledgementMode fallback = ShareAcknowledgementMode.IMPLICIT;\n}","preventionTips":["Null-check config-derived strings before passing to fromString().","When reading from properties/Map, supply a default with ConfigDef rather than letting null propagate.","Prefer the named constants ShareAcknowledgementMode.IMPLICIT / EXPLICIT when the value is fixed at compile time."],"tags":["share-consumer","config","null-safety"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}