didi/DoKit · error · IllegalArgumentException

Memory cache must not be null.

Error message

Memory cache must not be null.

What it means

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.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/DokitPicasso.java:750

     * Specify the executor service for loading images in the background.
     * <p>
     * Note: Calling {@link DokitPicasso#shutdown() shutdown()} will not shutdown supplied executors.
     */
    public Builder executor(ExecutorService executorService) {
      if (executorService == null) {
        throw new IllegalArgumentException("Executor service must not be null.");
      }
      if (this.service != null) {
        throw new IllegalStateException("Executor service already set.");
      }
      this.service = executorService;
      return this;
    }

    /** Specify the memory cache used for the most recent images. */
    public Builder memoryCache(Cache memoryCache) {
      if (memoryCache == null) {
        throw new IllegalArgumentException("Memory cache must not be null.");
      }
      if (this.cache != null) {
        throw new IllegalStateException("Memory cache already set.");
      }
      this.cache = memoryCache;
      return this;
    }

    /** Specify a listener for interesting events. */
    public Builder listener(Listener listener) {
      if (listener == null) {
        throw new IllegalArgumentException("Listener must not be null.");
      }
      if (this.listener != null) {
        throw new IllegalStateException("Listener already set.");
      }
      this.listener = listener;
      return this;

View on GitHub (pinned to 626827cddb)

Solutions

  1. Pass a non-null Cache such as new LruCache(context)
  2. Skip the memoryCache() call entirely to use the default cache
  3. Fix the source that produced the null cache reference

Example fix

// before
builder.memoryCache(null); // IllegalArgumentException

// after
builder.memoryCache(new LruCache(context));
Defensive patterns

Strategy: validation

Validate before calling

Cache cache = cacheProvider.cache();
if (cache != null) { builder.memoryCache(cache); } else { builder.memoryCache(new LruCache(context)); }

Prevention

When it happens

Trigger: Calling builder.memoryCache(null), typically because a cache field was never assigned or a factory returned null.

Common situations: DI containers returning null before initialization; test setups that omit a cache; code branches that build an LruCache only for certain build variants.

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/7f7b0729f408fc84. Report an issue: GitHub.