{"record":{"id":"02ae3e0cd205a8a3","repo":"didi/DoKit","slug":"height-must-be-positive-number-or-0","errorCode":null,"errorMessage":"Height must be positive number or 0.","messagePattern":"Height must be positive number or 0\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java","lineNumber":304,"sourceCode":"    /**\n     * Set the stable key to be used instead of the URI or resource ID when caching.\n     * Two requests with the same value are considered to be for the same resource.\n     */\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","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java#L286-L322","documentation":"Thrown by Request.Builder.resize(int, int) when targetHeight is negative. The width check has already passed, so only the second argument is at fault. As with width, 0 means 'keep aspect ratio' and anything below 0 is invalid.","triggerScenarios":"Calling resize(100, -1) or any resize() where targetHeight < 0.","commonSituations":"Forwarding LayoutParams.MATCH_PARENT (-1) or WRAP_CONTENT (-2) as a pixel height; using a height computed from an aspect-ratio calculation that went negative (bad source dimensions); defaulting a height variable to -1 as a sentinel.","solutions":["Clamp the height: resize(w, Math.max(0, h)).","Replace -1 sentinel values with 0 (the library's legal 'unspecified' value) before resizing.","Verify the height source (measured view, display metrics) and log it when it is negative."],"exampleFix":"// before\nint h = targetHeight != -1 ? targetHeight : -1; // sentinel leaks through\nbuilder.resize(width, h);\n\n// after\nint h = targetHeight != -1 ? targetHeight : 0; // 0 = keep aspect ratio\nbuilder.resize(width, h);","handlingStrategy":"validation","validationCode":"int safeHeight = Math.max(0, targetHeight);\nbuilder.resize(targetWidth, safeHeight);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid -1 sentinels for 'unspecified' height; use 0 which Picasso accepts.","Validate aspect-ratio math: negative results mean bad source dimensions, not valid targets."],"tags":["android","picasso","image-loading","validation","builder"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}