didi/DoKit · error · IllegalArgumentException

Bitmap may not be null.

Error message

Bitmap may not be null.

What it means

Downloader.Response's deprecated bitmap constructor throws IllegalArgumentException when bitmap is null. A Response built in bitmap mode must carry the decoded Bitmap; callers implementing a custom Downloader must pass a real bitmap. Fail-fast null guard.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Downloader.java:73

  /** Response stream or bitmap and info. */
  class Response {
    final InputStream stream;
    final Bitmap bitmap;
    final boolean cached;
    final long contentLength;

    /**
     * Response image and info.
     *
     * @param bitmap Image.
     * @param loadedFromCache {@code true} if the source of the image is from a local disk cache.
     * @deprecated Use {@link com.didichuxing.doraemonkit.picasso.RequestHandler} for directly loading {@link Bitmap} instances.
     */
    @Deprecated
    public Response(Bitmap bitmap, boolean loadedFromCache) {
      if (bitmap == null) {
        throw new IllegalArgumentException("Bitmap may not be null.");
      }
      this.stream = null;
      this.bitmap = bitmap;
      this.cached = loadedFromCache;
      this.contentLength = -1;
    }

    /**
     * Response stream and info.
     *
     * @param stream Image data stream.
     * @param loadedFromCache {@code true} if the source of the stream is from a local disk cache.
     * @deprecated Use {@link Response#Response(java.io.InputStream, boolean, long)} instead.
     */
    @Deprecated @SuppressWarnings("UnusedDeclaration")
    public Response(InputStream stream, boolean loadedFromCache) {
      this(stream, loadedFromCache, -1);
    }

View on GitHub (pinned to 626827cddb)

Solutions

  1. Only build the bitmap Response when you actually have a decoded Bitmap; otherwise build the stream Response or return null per the Downloader contract
  2. Migrate to the RequestHandler API, which the deprecation notice recommends for direct Bitmap loading
  3. Fix the decode path so failure returns an error instead of a null bitmap

Example fix

// before
Bitmap b = decodeFromCache(url);
return new Response(b, true); // IllegalArgumentException when b == null

// after
Bitmap b = decodeFromCache(url);
if (b != null) return new Response(b, true);
return new Response(openStream(url), false, contentLength);
Defensive patterns

Strategy: validation

Validate before calling

@Override public Response load(Uri uri, int policy) throws IOException {
  Bitmap b = decodeFromCache(uri);
  if (b != null) return new Response(b, true);
  return new Response(openStream(uri), false, contentLengthOf(uri));
}

Prevention

When it happens

Trigger: Implementing a custom Downloader and returning new Response((Bitmap) null, false) when the decode step fails or is skipped.

Common situations: Custom downloaders wrapping other caching layers where a cache miss yields null; code ported from newer Picasso where the Response API changed to RequestHandler.Result.

Related errors


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