{"record":{"id":"e8f7bda7a152aa99","repo":"didi/DoKit","slug":"memory-policy-cannot-be-null","errorCode":null,"errorMessage":"Memory policy cannot be null.","messagePattern":"Memory policy cannot be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":346,"sourceCode":"        data.transform(transformations);\n        return this;\n    }\n\n    /**\n     * @deprecated Use {@link #memoryPolicy(MemoryPolicy, MemoryPolicy...)} instead.\n     */\n    @Deprecated\n    public RequestCreator skipMemoryCache() {\n        return memoryPolicy(NO_CACHE, NO_STORE);\n    }\n\n    /**\n     * Specifies the {@link MemoryPolicy} to use for this request. You may specify additional policy\n     * options using the varargs parameter.\n     */\n    public RequestCreator memoryPolicy(MemoryPolicy policy, MemoryPolicy... additional) {\n        if (policy == null) {\n            throw new IllegalArgumentException(\"Memory policy cannot be null.\");\n        }\n        this.memoryPolicy |= policy.index;\n        if (additional == null) {\n            throw new IllegalArgumentException(\"Memory policy cannot be null.\");\n        }\n        if (additional.length > 0) {\n            for (MemoryPolicy memoryPolicy : additional) {\n                if (memoryPolicy == null) {\n                    throw new IllegalArgumentException(\"Memory policy cannot be null.\");\n                }\n                this.memoryPolicy |= memoryPolicy.index;\n            }\n        }\n        return this;\n    }\n\n    /**\n     * Specifies the {@link NetworkPolicy} to use for this request. You may specify additional policy","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L328-L364","documentation":"Thrown by RequestCreator.memoryPolicy(MemoryPolicy, MemoryPolicy...) when the required first policy argument is null. MemoryPolicy is an enum-like set of flags (NO_CACHE, NO_STORE) and a null primary policy indicates a programming error, rejected immediately with IllegalArgumentException.","triggerScenarios":"Calling memoryPolicy(null), or passing a nullable variable (e.g. a policy read from config/preferences) as the first argument: .memoryPolicy(maybeNullPolicy).","commonSituations":"Configuration-driven cache policies where the flag was absent from JSON/preferences and decoded to null; Kotlin call sites passing MemoryPolicy? without a null check; refactors away from the deprecated skipMemoryCache().","solutions":["Pass a non-null MemoryPolicy, e.g. memoryPolicy(NO_CACHE, NO_STORE) instead of the deprecated skipMemoryCache()","Guard nullable config values: memoryPolicy(policy != null ? policy : MemoryPolicy.NO_CACHE)","Default the config field to a concrete policy so it can never be null"],"exampleFix":"// before\nMemoryPolicy p = config.isCacheDisabled() ? MemoryPolicy.NO_CACHE : null;\npicasso.load(url).memoryPolicy(p).into(imageView); // throws when null\n\n// after\nRequestCreator rc = picasso.load(url);\nif (config.isCacheDisabled()) rc.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);\nrc.into(imageView);","handlingStrategy":"validation","validationCode":"MemoryPolicy p = (configPolicy != null) ? configPolicy : MemoryPolicy.NO_CACHE;\nrc.memoryPolicy(p);","typeGuard":"static MemoryPolicy requireMemoryPolicy(MemoryPolicy p) {\n    if (p == null) throw new IllegalArgumentException(\"MemoryPolicy required\");\n    return p;\n}","tryCatchPattern":null,"preventionTips":["Default nullable policy config to a concrete MemoryPolicy at load time","Prefer memoryPolicy(NO_CACHE, NO_STORE) over the deprecated skipMemoryCache()","Note the first policy is applied before the varargs checks, so a throw can leave partial state — avoid reusing that builder"],"tags":["picasso","dokit","android","image-loading","memory-policy","null-safety"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}