{"record":{"id":"b96858042b9a3249","repo":"didi/DoKit","slug":"target-must-not-be-null","errorCode":null,"errorMessage":"Target must not be null.","messagePattern":"Target must not be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":518,"sourceCode":"     *     frame.setBackgroundResource(R.drawable.profile_error);\n     *   }\n     *\n     *   {@literal @}Override public void onPrepareLoad(Drawable placeHolderDrawable) {\n     *     frame.setBackgroundDrawable(placeHolderDrawable);\n     *   }\n     * }\n     * </pre></blockquote>\n     * <p>\n     * <em>Note:</em> This method keeps a weak reference to the {@link Target} instance and will be\n     * garbage collected if you do not keep a strong reference to it. To receive callbacks when an\n     * image is loaded use {@link #into(android.widget.ImageView, Callback)}.\n     */\n    public void into(Target target) {\n        long started = System.nanoTime();\n        checkMain();\n\n        if (target == null) {\n            throw new IllegalArgumentException(\"Target must not be null.\");\n        }\n        if (deferred) {\n            throw new IllegalStateException(\"Fit cannot be used with a Target.\");\n        }\n\n        if (!data.hasImage()) {\n            picasso.cancelRequest(target);\n            target.onPrepareLoad(setPlaceholder ? getPlaceholderDrawable() : null);\n            return;\n        }\n\n        Request request = createRequest(started);\n        String requestKey = createKey(request);\n\n        if (shouldReadFromMemoryCache(memoryPolicy)) {\n            Bitmap bitmap = picasso.quickMemoryCacheCheck(requestKey);\n            if (bitmap != null) {\n                picasso.cancelRequest(target);","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L500-L536","documentation":"Thrown by RequestCreator.into(Target) when the Target argument is null. A Target receives the loaded bitmap callbacks, so a null target has nothing to deliver to; Picasso validates on the main thread (checkMain runs first) and throws IllegalArgumentException.","triggerScenarios":"Calling .into((Target) null), or passing a Target field that was not yet initialized / was nulled after a lifecycle event.","commonSituations":"Fields like custom Target instances referenced before initialization in onCreate; passing a weakly-held Target that was garbage-collected and left null; Kotlin nullable Target passed without !!-style checks.","solutions":["Pass a non-null Target implementation and keep a strong reference to it (into(Target) holds only a weak reference)","If the target is optional by the time the call runs, guard: if (target != null) rc.into(target); else rc.fetch(null);","Initialize the Target field before building the request chain"],"exampleFix":"// before\nprivate Target target; // not yet assigned\npicasso.load(url).into(target); // throws \"Target must not be null.\"\n\n// after\ntarget = new Target() { /* onBitmapLoaded/onBitmapFailed */ };\npicasso.load(url).into(target);","handlingStrategy":"validation","validationCode":"if (target != null) {\n    picasso.load(url).into(target);\n} else {\n    picasso.load(url).fetch(null); // warm cache instead\n}","typeGuard":"static boolean isUsableTarget(Target t) {\n    return t != null;\n}","tryCatchPattern":null,"preventionTips":["Initialize Target fields before any load call","Keep a strong reference to the Target for as long as you need callbacks — into(Target) holds only a weak one","Prefer into(imageView, callback) when the destination is really an ImageView"],"tags":["picasso","dokit","android","image-loading","target","null-safety"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}