{"record":{"id":"7f7b0729f408fc84","repo":"didi/DoKit","slug":"memory-cache-must-not-be-null","errorCode":null,"errorMessage":"Memory cache must not be null.","messagePattern":"Memory cache must not be null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java","lineNumber":750,"sourceCode":"     * Specify the executor service for loading images in the background.\n     * <p>\n     * Note: Calling {@link DokitPicasso#shutdown() shutdown()} will not shutdown supplied executors.\n     */\n    public Builder executor(ExecutorService executorService) {\n      if (executorService == null) {\n        throw new IllegalArgumentException(\"Executor service must not be null.\");\n      }\n      if (this.service != null) {\n        throw new IllegalStateException(\"Executor service already set.\");\n      }\n      this.service = executorService;\n      return this;\n    }\n\n    /** Specify the memory cache used for the most recent images. */\n    public Builder memoryCache(Cache memoryCache) {\n      if (memoryCache == null) {\n        throw new IllegalArgumentException(\"Memory cache must not be null.\");\n      }\n      if (this.cache != null) {\n        throw new IllegalStateException(\"Memory cache already set.\");\n      }\n      this.cache = memoryCache;\n      return this;\n    }\n\n    /** Specify a listener for interesting events. */\n    public Builder listener(Listener listener) {\n      if (listener == null) {\n        throw new IllegalArgumentException(\"Listener must not be null.\");\n      }\n      if (this.listener != null) {\n        throw new IllegalStateException(\"Listener already set.\");\n      }\n      this.listener = listener;\n      return this;","sourceCodeStart":732,"sourceCodeEnd":768,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java#L732-L768","documentation":"DokitPicasso.Builder.memoryCache() throws IllegalArgumentException when passed a null Cache. Picasso needs a memory cache instance to store recent bitmaps. This is a fail-fast null guard on builder configuration.","triggerScenarios":"Calling builder.memoryCache(null), typically because a cache field was never assigned or a factory returned null.","commonSituations":"DI containers returning null before initialization; test setups that omit a cache; code branches that build an LruCache only for certain build variants.","solutions":["Pass a non-null Cache such as new LruCache(context)","Skip the memoryCache() call entirely to use the default cache","Fix the source that produced the null cache reference"],"exampleFix":"// before\nbuilder.memoryCache(null); // IllegalArgumentException\n\n// after\nbuilder.memoryCache(new LruCache(context));","handlingStrategy":"validation","validationCode":"Cache cache = cacheProvider.cache();\nif (cache != null) { builder.memoryCache(cache); } else { builder.memoryCache(new LruCache(context)); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to new LruCache(context) when unsure","Never pass a nullable cache variable; decide the default in the same scope"],"tags":["android","picasso","builder","null-check","cache"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}