{"record":{"id":"de1a1575dd344a36","repo":"didi/DoKit","slug":"at-least-one-dimension-has-to-be-positive-number","errorCode":null,"errorMessage":"At least one dimension has to be positive number.","messagePattern":"At least one dimension has to be positive number\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java","lineNumber":307,"sourceCode":"     */\n    public Builder stableKey(String stableKey) {\n      this.stableKey = stableKey;\n      return this;\n    }\n\n    /**\n     * Resize the image to the specified size in pixels.\n     * Use 0 as desired dimension to resize keeping aspect ratio.\n     */\n    public Builder resize(int targetWidth, int targetHeight) {\n      if (targetWidth < 0) {\n        throw new IllegalArgumentException(\"Width must be positive number or 0.\");\n      }\n      if (targetHeight < 0) {\n        throw new IllegalArgumentException(\"Height must be positive number or 0.\");\n      }\n      if (targetHeight == 0 && targetWidth == 0) {\n        throw new IllegalArgumentException(\"At least one dimension has to be positive number.\");\n      }\n      this.targetWidth = targetWidth;\n      this.targetHeight = targetHeight;\n      return this;\n    }\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","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java#L289-L325","documentation":"Thrown by Request.Builder.resize(int, int) when both targetWidth and targetHeight are 0. Picasso uses 0 to mean 'derive this dimension from the other one to keep aspect ratio'; if both are 0 there is nothing to scale to, so the request is rejected.","triggerScenarios":"Calling resize(0, 0), or resize(w, h) where both variables resolve to 0 at runtime (e.g., uninitialized fields, view not yet measured).","commonSituations":"Building the request before the target view is laid out (getWidth()/getHeight() both 0); passing two 'unspecified' sentinel zeros; copying sample code that hardcodes resize(0, 0).","solutions":["Ensure at least one dimension is a positive pixel value; check both before calling resize.","Defer image loading until the view is measured (onLayoutChanged / ViewTreeObserver.OnGlobalLayoutListener) or use Picasso's fit() instead of resize().","If only width is known, call resize(width, 0) — height is derived automatically."],"exampleFix":"// before\npicasso.load(url).resize(imageView.getWidth(), imageView.getHeight()).into(imageView); // both 0 pre-layout\n\n// after\npicasso.load(url).fit().centerInside().into(imageView); // sizes to the view at request time","handlingStrategy":"validation","validationCode":"if (targetWidth > 0 || targetHeight > 0) {\n  builder.resize(targetWidth, targetHeight);\n} else {\n  // defer until the view is measured, or use fit()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use fit() instead of resize() when sizing to an ImageView.","Trigger loads from onGlobalLayout / doOnLayout when dimensions come from a view.","Treat both-dimensions-zero as 'not ready to load', not as a valid request."],"tags":["android","picasso","image-loading","validation","view-layout"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}