{"record":{"id":"9f5f43f3e235522b","repo":"didi/DoKit","slug":"stream-may-not-be-null","errorCode":null,"errorMessage":"Stream may not be null.","messagePattern":"Stream may not be null\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Downloader.java","lineNumber":118,"sourceCode":"     * @deprecated The {@code contentLength} argument value is ignored. Use {@link #Response(Bitmap,\n     * boolean)}.\n     */\n    @Deprecated @SuppressWarnings(\"UnusedDeclaration\")\n    public Response(Bitmap bitmap, boolean loadedFromCache, long contentLength) {\n      this(bitmap, loadedFromCache);\n    }\n\n    /**\n     * Response stream and info.\n     *\n     * @param stream Image data stream.\n     * @param loadedFromCache {@code true} if the source of the stream is from a local disk cache.\n     * @param contentLength The content length of the response, typically derived by the\n     * {@code Content-Length} HTTP header.\n     */\n    public Response(InputStream stream, boolean loadedFromCache, long contentLength) {\n      if (stream == null) {\n        throw new IllegalArgumentException(\"Stream may not be null.\");\n      }\n      this.stream = stream;\n      this.bitmap = null;\n      this.cached = loadedFromCache;\n      this.contentLength = contentLength;\n    }\n\n    /**\n     * Input stream containing image data.\n     * <p>\n     * If this returns {@code null}, image data will be available via {@link #getBitmap()}.\n     */\n    public InputStream getInputStream() {\n      return stream;\n    }\n\n    /**\n     * Bitmap representing the image.","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Downloader.java#L100-L136","documentation":"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.","triggerScenarios":"Implementing a custom Downloader and returning new Response(null, false, contentLength) when the connection or cache stream could not be opened.","commonSituations":"Custom downloaders where openStream() fails silently and returns null instead of throwing; wrappers around okhttp whose body().byteStream() was consumed or closed earlier.","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"],"exampleFix":"// before\nInputStream is = openQuietly(url);\nreturn new Response(is, false, len); // IllegalArgumentException when is == null\n\n// after\nInputStream is = openStream(url); // throws IOException on failure\nreturn new Response(is, false, len);","handlingStrategy":"validation","validationCode":"InputStream is = urlConnection.getInputStream(); // throws IOException on failure\nreturn new Response(is, false, urlConnection.getContentLength());","typeGuard":null,"tryCatchPattern":"try { return new Response(open(url), false, len); } catch (IllegalArgumentException e) { throw new IOException(\"stream open failed\", e); }","preventionTips":["Open streams with methods that throw on failure rather than returning null","Never construct a stream Response from an already-consumed or closed stream"],"tags":["android","picasso","downloader","null-check","network"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}