didi/DoKit · error · IllegalArgumentException
Stream may not be null.
Error message
Stream may not be null.
What it means
Downloader.Response's stream constructor throws IllegalArgumentException when stream is null. A Response in stream mode must expose the image bytes through an InputStream; a custom Downloader must pass an open stream. Fail-fast null guard.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Downloader.java:118
* @deprecated The {@code contentLength} argument value is ignored. Use {@link #Response(Bitmap,
* boolean)}.
*/
@Deprecated @SuppressWarnings("UnusedDeclaration")
public Response(Bitmap bitmap, boolean loadedFromCache, long contentLength) {
this(bitmap, loadedFromCache);
}
/**
* 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.
* @param contentLength The content length of the response, typically derived by the
* {@code Content-Length} HTTP header.
*/
public Response(InputStream stream, boolean loadedFromCache, long contentLength) {
if (stream == null) {
throw new IllegalArgumentException("Stream may not be null.");
}
this.stream = stream;
this.bitmap = null;
this.cached = loadedFromCache;
this.contentLength = contentLength;
}
/**
* Input stream containing image data.
* <p>
* If this returns {@code null}, image data will be available via {@link #getBitmap()}.
*/
public InputStream getInputStream() {
return stream;
}
/**
* Bitmap representing the image.View on GitHub (pinned to 626827cddb)
Solutions
- Return a real, open InputStream in the Response
- If the stream cannot be opened, throw an IOException from the Downloader instead of constructing a Response with null
- Verify the underlying connection/cache actually produced a stream before building the Response
Example fix
// before InputStream is = openQuietly(url); return new Response(is, false, len); // IllegalArgumentException when is == null // after InputStream is = openStream(url); // throws IOException on failure return new Response(is, false, len);
Defensive patterns
Strategy: validation
Validate before calling
InputStream is = urlConnection.getInputStream(); // throws IOException on failure return new Response(is, false, urlConnection.getContentLength());
Try / catch
try { return new Response(open(url), false, len); } catch (IllegalArgumentException e) { throw new IOException("stream open failed", e); } Prevention
- Open streams with methods that throw on failure rather than returning null
- Never construct a stream Response from an already-consumed or closed stream
When it happens
Trigger: Implementing a custom Downloader and returning new Response(null, false, contentLength) when the connection or cache stream could not be opened.
Common situations: Custom downloaders where openStream() fails silently and returns null instead of throwing; wrappers around okhttp whose body().byteStream() was consumed or closed earlier.
Related errors
- Bitmap may not be null.
- Downloader must not be null.
- Executor service must not be null.
- Memory cache must not be null.
- Listener must not be null.
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/9f5f43f3e235522b.
Report an issue: GitHub.