{"record":{"id":"da6eda1e530b169f","repo":"didi/DoKit","slug":"center-crop-requires-calling-resize-with-positive","errorCode":null,"errorMessage":"Center crop requires calling resize with positive width and height.","messagePattern":"Center crop requires calling resize with positive width and height\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java","lineNumber":460,"sourceCode":"     * Custom transformations will always be run after the built-in transformations.\n     */\n    public Builder transform(List<? extends Transformation> transformations) {\n      if (transformations == null) {\n        throw new IllegalArgumentException(\"Transformation list must not be null.\");\n      }\n      for (int i = 0, size = transformations.size(); i < size; i++) {\n        transform(transformations.get(i));\n      }\n      return this;\n    }\n\n    /** Create the immutable {@link Request} object. */\n    public Request build() {\n      if (centerInside && centerCrop) {\n        throw new IllegalStateException(\"Center crop and center inside can not be used together.\");\n      }\n      if (centerCrop && (targetWidth == 0 && targetHeight == 0)) {\n        throw new IllegalStateException(\n            \"Center crop requires calling resize with positive width and height.\");\n      }\n      if (centerInside && (targetWidth == 0 && targetHeight == 0)) {\n        throw new IllegalStateException(\n            \"Center inside requires calling resize with positive width and height.\");\n      }\n      if (priority == null) {\n        priority = Priority.NORMAL;\n      }\n      return new Request(uri, resourceId, stableKey, transformations, targetWidth, targetHeight,\n          centerCrop, centerInside, onlyScaleDown, rotationDegrees, rotationPivotX, rotationPivotY,\n          hasRotationPivot, config, priority);\n    }\n  }\n}\n","sourceCodeStart":442,"sourceCodeEnd":476,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java#L442-L476","documentation":"Thrown by Request.Builder.build() when centerCrop was set but no resize target exists (both targetWidth and targetHeight are 0). Center-crop needs explicit bounds to know what to fill and where to crop; without them the operation is undefined.","triggerScenarios":"Chaining .centerCrop() with no .resize(w, h) (or after clearResize()) and then building/into().","commonSituations":"Copy-pasting a chain but dropping the resize call; calling clearResize() in shared code while keeping centerCrop; expecting centerCrop() alone to size to the view (that is what fit() is for).","solutions":["Add .resize(width, height) with at least one positive dimension before .centerCrop().","If sizing to an ImageView, use .fit().centerCrop() instead of explicit resize.","Check for clearResize() calls in shared builders that invalidate the resize target."],"exampleFix":"// before\npicasso.load(url).centerCrop().into(imageView);\n\n// after\npicasso.load(url).fit().centerCrop().into(imageView); // or .resize(400, 400).centerCrop()","handlingStrategy":"validation","validationCode":"if (targetWidth > 0 || targetHeight > 0) { builder.resize(w, h).centerCrop(); } else { builder.fit().centerCrop(); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair every centerCrop() with a resize() or use fit().","clearResize() invalidates centerCrop; clear both if clearing."],"tags":["android","picasso","image-loading","builder","ordering"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}