{"record":{"id":"abd552f9e232e11e","repo":"didi/DoKit","slug":"placeholder-image-already-set","errorCode":null,"errorMessage":"Placeholder image already set.","messagePattern":"Placeholder image already set\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java","lineNumber":97,"sourceCode":"\n    RequestCreator() {\n        this.picasso = null;\n        this.data = new Request.Builder(null, 0, null);\n    }\n\n    /**\n     * Explicitly opt-out to having a placeholder set when calling {@code into}.\n     * <p>\n     * By default, Picasso will either set a supplied placeholder or clear the target\n     * {@link ImageView} in order to ensure behavior in situations where views are recycled. This\n     * method will prevent that behavior and retain any already set image.\n     */\n    public RequestCreator noPlaceholder() {\n        if (placeholderResId != 0) {\n            throw new IllegalStateException(\"Placeholder resource already set.\");\n        }\n        if (placeholderDrawable != null) {\n            throw new IllegalStateException(\"Placeholder image already set.\");\n        }\n        setPlaceholder = false;\n        return this;\n    }\n\n    /**\n     * A placeholder drawable to be used while the image is being loaded. If the requested image is\n     * not immediately available in the memory cache then this resource will be set on the target\n     * {@link ImageView}.\n     */\n    public RequestCreator placeholder(int placeholderResId) {\n        if (!setPlaceholder) {\n            throw new IllegalStateException(\"Already explicitly declared as no placeholder.\");\n        }\n        if (placeholderResId == 0) {\n            throw new IllegalArgumentException(\"Placeholder image resource invalid.\");\n        }\n        if (placeholderDrawable != null) {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/RequestCreator.java#L79-L115","documentation":"Thrown by RequestCreator.noPlaceholder() when a placeholder Drawable was already set via placeholder(Drawable). It is the Drawable variant of the resource guard: once any placeholder exists, opting out of placeholders on the same creator is a contradiction and fails fast.","triggerScenarios":"Chaining .placeholder(drawable).noPlaceholder() on the same RequestCreator.","commonSituations":"Default placeholder drawable applied in shared loading code, then noPlaceholder() added at a specific call site; refactoring that merges a placeholder branch with a no-placeholder branch.","solutions":["Use exactly one of placeholder(Drawable) or noPlaceholder() per request.","Push the placeholder decision into one helper parameter (e.g., placeholderResId, 0 = none).","Grep request chains for both '.placeholder(' and '.noPlaceholder()' appearing together."],"exampleFix":"// before\npublic void show(String url, Drawable ph) {\n  RequestCreator c = picasso.load(url).placeholder(ph);\n  if (ph == null) c.noPlaceholder(); // throws when ph != null path already set it\n}\n\n// after\npublic void show(String url, Drawable ph) {\n  RequestCreator c = picasso.load(url);\n  if (ph != null) c.placeholder(ph); else c.noPlaceholder();\n}","handlingStrategy":"validation","validationCode":"RequestCreator c = picasso.load(url);\nif (placeholderDrawable != null) c.placeholder(placeholderDrawable); else c.noPlaceholder();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Model the placeholder as one optional value (resId XOR drawable XOR none).","Never call noPlaceholder() after any placeholder was set on the same creator."],"tags":["android","picasso","builder","state-conflict","placeholder"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}