didi/DoKit · error · IllegalArgumentException

Height must be positive number or 0.

Error message

Height must be positive number or 0.

What it means

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.

Source

Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java:304

    /**
     * Set the stable key to be used instead of the URI or resource ID when caching.
     * Two requests with the same value are considered to be for the same resource.
     */
    public Builder stableKey(String stableKey) {
      this.stableKey = stableKey;
      return this;
    }

    /**
     * Resize the image to the specified size in pixels.
     * Use 0 as desired dimension to resize keeping aspect ratio.
     */
    public Builder resize(int targetWidth, int targetHeight) {
      if (targetWidth < 0) {
        throw new IllegalArgumentException("Width must be positive number or 0.");
      }
      if (targetHeight < 0) {
        throw new IllegalArgumentException("Height must be positive number or 0.");
      }
      if (targetHeight == 0 && targetWidth == 0) {
        throw new IllegalArgumentException("At least one dimension has to be positive number.");
      }
      this.targetWidth = targetWidth;
      this.targetHeight = targetHeight;
      return this;
    }

    /** Clear the resize transformation, if any. This will also clear center crop/inside if set. */
    public Builder clearResize() {
      targetWidth = 0;
      targetHeight = 0;
      centerCrop = false;
      centerInside = false;
      return this;
    }

View on GitHub (pinned to 626827cddb)

Solutions

  1. Clamp the height: resize(w, Math.max(0, h)).
  2. Replace -1 sentinel values with 0 (the library's legal 'unspecified' value) before resizing.
  3. Verify the height source (measured view, display metrics) and log it when it is negative.

Example fix

// before
int h = targetHeight != -1 ? targetHeight : -1; // sentinel leaks through
builder.resize(width, h);

// after
int h = targetHeight != -1 ? targetHeight : 0; // 0 = keep aspect ratio
builder.resize(width, h);
Defensive patterns

Strategy: validation

Validate before calling

int safeHeight = Math.max(0, targetHeight);
builder.resize(targetWidth, safeHeight);

Prevention

When it happens

Trigger: Calling resize(100, -1) or any resize() where targetHeight < 0.

Common situations: 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.

Related errors


AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14). Data as JSON: /api/errors/02ae3e0cd205a8a3. Report an issue: GitHub.