{"record":{"id":"b3d05eb3347da855","repo":"didi/DoKit","slug":"center-inside-can-not-be-used-after-calling-center","errorCode":null,"errorMessage":"Center inside can not be used after calling centerCrop","messagePattern":"Center inside can not be used after calling centerCrop","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java","lineNumber":348,"sourceCode":"        throw new IllegalStateException(\"Center crop can not be used after calling centerInside\");\n      }\n      centerCrop = true;\n      return this;\n    }\n\n    /** Clear the center crop transformation flag, if set. */\n    public Builder clearCenterCrop() {\n      centerCrop = false;\n      return this;\n    }\n\n    /**\n     * Centers an image inside of the bounds specified by {@link #resize(int, int)}. This scales\n     * the image so that both dimensions are equal to or less than the requested bounds.\n     */\n    public Builder centerInside() {\n      if (centerCrop) {\n        throw new IllegalStateException(\"Center inside can not be used after calling centerCrop\");\n      }\n      centerInside = true;\n      return this;\n    }\n\n    /** Clear the center inside transformation flag, if set. */\n    public Builder clearCenterInside() {\n      centerInside = false;\n      return this;\n    }\n\n    /**\n     * Only resize an image if the original image size is bigger than the target size\n     * specified by {@link #resize(int, int)}.\n     */\n    public Builder onlyScaleDown() {\n      if (targetHeight == 0 && targetWidth == 0) {\n        throw new IllegalStateException(\"onlyScaleDown can not be applied without resize\");","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java#L330-L366","documentation":"Thrown by Request.Builder.centerInside() when centerCrop() was already called on the same builder. It is the mirror of the centerCrop() guard: the two scaling strategies are mutually exclusive and Picasso enforces this as soon as the second one is set.","triggerScenarios":"Chaining .centerCrop().centerInside(), or calling centerCrop() in shared setup code and centerInside() later on the same builder.","commonSituations":"Common builder template that applies centerCrop(), then a list item path adds centerInside(); merging code from two examples; conditional logic that adds both branches.","solutions":["Pick one strategy per request and remove the other call.","Call clearCenterCrop() before centerInside() if the builder legitimately carries a stale flag.","Make the crop strategy an explicit parameter of your helper method so both branches can never run."],"exampleFix":"// before\npublic RequestCreator thumb(String url) {\n  return picasso.load(url).resize(100, 100).centerCrop().centerInside();\n}\n\n// after\npublic RequestCreator thumb(String url, boolean crop) {\n  RequestCreator c = picasso.load(url).resize(100, 100);\n  return crop ? c.centerCrop() : c.centerInside();\n}","handlingStrategy":"validation","validationCode":"if (!builderHasCenterCrop) { builder.centerInside(); } // guard shared-builder paths","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never chain both centerCrop() and centerInside() on one request.","Audit shared builder templates for pre-applied crop flags.","Wrap Picasso calls in a single app-level image loader that owns the strategy."],"tags":["android","picasso","image-loading","builder","state-conflict"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}