{"id":"9778fbce74d77926","repo":"apache/kafka","slug":"shareacquiremode-is-null","errorCode":null,"errorMessage":"ShareAcquireMode is null","messagePattern":"ShareAcquireMode is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareAcquireMode.java","lineNumber":44,"sourceCode":"public enum ShareAcquireMode {\n    BATCH_OPTIMIZED(\"batch_optimized\", (byte) 0),\n    RECORD_LIMIT(\"record_limit\", (byte) 1);\n\n    public final String name;\n\n    final byte id;\n\n    ShareAcquireMode(final String name, final byte id) {\n        this.name = name;\n        this.id = id;\n    }\n\n    /**\n     * Case-insensitive acquire mode lookup by string name.\n     */\n    public static ShareAcquireMode of(final String name) {\n        if (name == null) {\n            throw new IllegalArgumentException(\"ShareAcquireMode is null\");\n        }\n        try {\n            return ShareAcquireMode.valueOf(name.toUpperCase(Locale.ROOT));\n        } catch (IllegalArgumentException e) {\n            throw new IllegalArgumentException(\"Invalid value `\" + name + \"` for configuration \" +\n                name + \". The value must either be 'batch_optimized' or 'record_limit'.\");\n        }\n    }\n\n    public byte id() {\n        return id;\n    }\n\n    public static ShareAcquireMode forId(byte id) {\n        switch (id) {\n            case 0:\n                return BATCH_OPTIMIZED;\n            case 1:","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareAcquireMode.java#L26-L62","documentation":"Thrown by ShareAcquireMode.of(String) when the supplied name is null. of() is the case-insensitive lookup that maps a config string to one of BATCH_OPTIMIZED or RECORD_LIMIT; a null input means the caller (usually the config layer) did not supply a value at all. This is a programmer/config error surfaced before any network activity.","triggerScenarios":"Calling ShareAcquireMode.of(null) directly; the ShareAcquireMode.Validator running of() on a config property whose value resolved to null; passing a Map.get() result for share.acquire.mode without a default.","commonSituations":"Omitting share.acquire.mode while the share consumer requires it; using a placeholder (e.g. ${SHARE_ACQUIRE_MODE}) that resolved to null; building configs programmatically from a Map missing the key.","solutions":["Set share.acquire.mode to either \"batch_optimized\" or \"record_limit\" in consumer config.","Default the value programmatically: props.getOrDefault(\"share.acquire.mode\", \"batch_optimized\").","Null-check the resolved config value at the boundary so the error message points at the missing property."],"exampleFix":"// before\nString mode = (String) props.get(\"share.acquire.mode\");\nShareAcquireMode.of(mode); // throws if key absent\n\n// after\nString mode = (String) props.getOrDefault(\"share.acquire.mode\", \"batch_optimized\");\nShareAcquireMode.of(mode);","handlingStrategy":"validation","validationCode":"// Validate the acquire-mode string before calling ShareAcquireMode.of().\nString acquireMode = /* user/config supplied */ ;\nif (acquireMode == null) {\n    throw new IllegalArgumentException(\n        \"share acquire mode must not be null; expected 'batch_optimized' or 'record_limit'\");\n}\nShareAcquireMode.of(acquireMode);","typeGuard":"java.util.function.Function<String, ShareAcquireMode> safeOf = s -> {\n    if (s == null) {\n        throw new IllegalArgumentException(\n            \"ShareAcquireMode is null; expected 'batch_optimized' or 'record_limit'\");\n    }\n    return ShareAcquireMode.of(s);\n};","tryCatchPattern":"try {\n    ShareAcquireMode.of(acquireMode);\n} catch (IllegalArgumentException ex) {\n    // null or unknown acquire mode; default to a safe value or surface to the user\n    ShareAcquireMode fallback = ShareAcquireMode.BATCH_OPTIMIZED;\n}","preventionTips":["Null-check config-derived acquire-mode strings before calling of().","Provide a default value via ConfigDef so the property never reaches of() as null.","Prefer the ShareAcquireMode enum constants directly when the choice is fixed at compile time.","Use ShareAcquireMode.Validator at config-load time to catch null/invalid values before runtime."],"tags":["share-consumer","config","null-safety"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}