{"record":{"id":"a020117606f0a7af","repo":"didi/DoKit","slug":"fit-cannot-be-used-with-fetch","errorCode":null,"errorMessage":"Fit cannot be used with fetch.","messagePattern":"Fit cannot be used with fetch\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":441,"sourceCode":"     */\n    public void fetch() {\n        fetch(null);\n    }\n\n    /**\n     * Asynchronously fulfills the request without a {@link ImageView} or {@link Target},\n     * and invokes the target {@link Callback} with the result. This is useful when you want to warm\n     * up the cache with an image.\n     * <p>\n     * <em>Note:</em> The {@link Callback} param is a strong reference and will prevent your\n     * {@link android.app.Activity} or {@link android.app.Fragment} from being garbage collected\n     * until the request is completed.\n     */\n    public void fetch(Callback callback) {\n        long started = System.nanoTime();\n\n        if (deferred) {\n            throw new IllegalStateException(\"Fit cannot be used with fetch.\");\n        }\n        if (data.hasImage()) {\n            // Fetch requests have lower priority by default.\n            if (!data.hasPriority()) {\n                data.priority(Priority.LOW);\n            }\n\n            Request request = createRequest(started);\n            String key = createKey(request, new StringBuilder());\n            Bitmap bitmap = picasso.quickMemoryCacheCheck(key);\n\n            if (bitmap != null) {\n                if (picasso.loggingEnabled) {\n                    log(OWNER_MAIN, VERB_COMPLETED, request.plainId(), \"from \" + MEMORY);\n                }\n                if (callback != null) {\n                    callback.onSuccess();\n                }","sourceCodeStart":423,"sourceCodeEnd":459,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L423-L459","documentation":"Thrown by RequestCreator.fetch(Callback) when the chain called fit(). fit() defers the request until a target ImageView is laid out and measured; fetch() has no view target at all (it warms the cache), so the combination is rejected with IllegalStateException.","triggerScenarios":"Calling picasso.load(url).fit().fetch(...), typically while refactoring an into(imageView) chain into a cache-warming prefetch.","commonSituations":"Preloading the next screen's images by copy-pasting the render chain (with fit()) and swapping into() for fetch(); RecyclerView prefetch helpers reusing the same builder configuration for both display and warm-up.","solutions":["Remove fit() from the fetch() chain and size explicitly: .resize(w, h).fetch(null)","Duplicate the chain: keep fit()+into(imageView) for display and a separate resize()+fetch() for prefetch","Pass null as the callback if you only want cache warming, and drop fit()"],"exampleFix":"// before\npicasso.load(url).fit().fetch(null); // throws \"Fit cannot be used with fetch.\"\n\n// after\npicasso.load(url).resize(targetWidth, targetHeight).centerInside().fetch(null);","handlingStrategy":"validation","validationCode":"// Prefetch path: explicit size, no fit\npicasso.load(url).resize(targetW, targetH).centerInside().fetch(null);\n// Display path: fit is fine\npicasso.load(url).fit().into(imageView);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep separate chain builders for display (fit allowed) and cache warm-up (no fit)","Pass null callback to fetch() when callbacks are not needed","Mirror the target view's dimensions with resize() so prefetched entries actually hit the cache key used later"],"tags":["picasso","dokit","android","image-loading","fit","prefetch"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}