{"record":{"id":"103d9a5e425c4f12","repo":"didi/DoKit","slug":"center-crop-can-not-be-used-after-calling-centerin","errorCode":null,"errorMessage":"Center crop can not be used after calling centerInside","messagePattern":"Center crop can not be used after calling centerInside","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java","lineNumber":330,"sourceCode":"    }\n\n    /** Clear the resize transformation, if any. This will also clear center crop/inside if set. */\n    public Builder clearResize() {\n      targetWidth = 0;\n      targetHeight = 0;\n      centerCrop = false;\n      centerInside = false;\n      return this;\n    }\n\n    /**\n     * Crops an image inside of the bounds specified by {@link #resize(int, int)} rather than\n     * distorting the aspect ratio. This cropping technique scales the image so that it fills the\n     * requested bounds and then crops the extra.\n     */\n    public Builder centerCrop() {\n      if (centerInside) {\n        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\");","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java#L312-L348","documentation":"Thrown by Request.Builder.centerCrop() when centerInside() was already called on the same builder. The two transformations are mutually exclusive crop strategies (fill-and-crop vs fit-within), so Picasso prevents combining them at setter time with an IllegalStateException.","triggerScenarios":"Chaining .centerInside().centerCrop() or calling centerInside() earlier (e.g., in shared builder-setup code) and centerCrop() later on the same builder instance.","commonSituations":"A shared helper that pre-configures a builder with centerInside(), then per-call code adds centerCrop(); copy-paste of request chains from different samples; refactoring that merges two code paths.","solutions":["Use only one of centerCrop()/centerInside() per request; delete the conflicting call.","If the builder is reused, call clearCenterInside() before centerCrop().","Split shared builder setup so crop policy is decided in exactly one place."],"exampleFix":"// before\nRequestCreator c = picasso.load(url).resize(200, 200).centerInside();\nc.centerCrop(); // throws\n\n// after\nRequestCreator c = picasso.load(url).resize(200, 200).centerInside();\n// or, for fill-and-crop behavior:\nRequestCreator c2 = picasso.load(url).resize(200, 200).centerCrop();","handlingStrategy":"validation","validationCode":"// Decide the strategy once before building the request\nboolean useCrop = /* single source of truth */;\nRequestCreator c = picasso.load(url).resize(w, h);\nif (useCrop) c.centerCrop(); else c.centerInside();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep crop policy in one parameter/flag rather than chaining both calls.","Remember centerCrop() and centerInside() are mutually exclusive by design.","Call clearCenterInside()/clearCenterCrop() when reusing builders."],"tags":["android","picasso","image-loading","builder","state-conflict"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}