{"record":{"id":"dac3cb62e073efd5","repo":"didi/DoKit","slug":"error-image-may-not-be-null","errorCode":null,"errorMessage":"Error image may not be null.","messagePattern":"Error image may not be null\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":160,"sourceCode":"     * An error drawable to be used if the request image could not be loaded.\n     */\n    public RequestCreator error(int errorResId) {\n        if (errorResId == 0) {\n            throw new IllegalArgumentException(\"Error image resource invalid.\");\n        }\n        if (errorDrawable != null) {\n            throw new IllegalStateException(\"Error image already set.\");\n        }\n        this.errorResId = errorResId;\n        return this;\n    }\n\n    /**\n     * An error drawable to be used if the request image could not be loaded.\n     */\n    public RequestCreator error(Drawable errorDrawable) {\n        if (errorDrawable == null) {\n            throw new IllegalArgumentException(\"Error image may not be null.\");\n        }\n        if (errorResId != 0) {\n            throw new IllegalStateException(\"Error image already set.\");\n        }\n        this.errorDrawable = errorDrawable;\n        return this;\n    }\n\n    /**\n     * Assign a tag to this request. Tags are an easy way to logically associate\n     * related requests that can be managed together e.g. paused, resumed,\n     * or canceled.\n     * <p>\n     * You can either use simple {@link String} tags or objects that naturally\n     * define the scope of your requests within your app such as a\n     * {@link android.content.Context}, an {@link android.app.Activity}, or a\n     * {@link android.app.Fragment}.\n     *","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L142-L178","documentation":"Thrown by RequestCreator.error(Drawable) when null is passed. Unlike placeholder(Drawable), which explicitly accepts null to clear an image, the error image cannot be null — Picasso needs something concrete to show on failure and throws IllegalArgumentException.","triggerScenarios":"Calling .error((Drawable) null) directly, or passing a field/getter that returned null (e.g. ContextCompat.getDrawable returning null was not checked, or a nullable field).","commonSituations":"Kotlin call sites passing a nullable Drawable without null handling; helper methods like getErrorDrawable() that can return null; copy-pasting the placeholder(null-to-clear) idiom onto error().","solutions":["Pass a non-null Drawable, e.g. ContextCompat.getDrawable(context, R.drawable.err) after a null check","Use error(int) with a valid resource id when you only have a resource reference","If 'no error image' is intended, omit the error() call entirely","In Kotlin, mark the parameter non-null or use errorResId.takeIf { it != 0 }?.let { builder.error(it) }"],"exampleFix":"// before\nDrawable d = ContextCompat.getDrawable(context, R.drawable.err); // may be null\npicasso.load(url).error(d).into(imageView); // throws \"Error image may not be null.\"\n\n// after\nDrawable d = ContextCompat.getDrawable(context, R.drawable.err);\nRequestCreator rc = picasso.load(url);\nif (d != null) rc.error(d); else rc.error(R.drawable.err);\nrc.into(imageView);","handlingStrategy":"validation","validationCode":"Drawable d = ContextCompat.getDrawable(context, R.drawable.err);\nif (d != null) {\n    rc.error(d);\n} else {\n    rc.error(R.drawable.err);\n}","typeGuard":"static Drawable requireErrorDrawable(Drawable d) {\n    if (d == null) throw new IllegalArgumentException(\"Error drawable required\");\n    return d;\n}","tryCatchPattern":null,"preventionTips":["Remember error(Drawable) rejects null while placeholder(Drawable) accepts it — the asymmetry trips people","Null-check ContextCompat.getDrawable results before use","In Kotlin, declare the parameter as non-null Drawable so the compiler blocks null"],"tags":["picasso","dokit","android","image-loading","null-safety","validation"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}