didi/DoKit · error · IllegalStateException

Center crop can not be used after calling centerInside

Error message

Center crop can not be used after calling centerInside

What it means

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.

Source

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

    }

    /** 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;
    }

    /**
     * Crops an image inside of the bounds specified by {@link #resize(int, int)} rather than
     * distorting the aspect ratio. This cropping technique scales the image so that it fills the
     * requested bounds and then crops the extra.
     */
    public Builder centerCrop() {
      if (centerInside) {
        throw new IllegalStateException("Center crop can not be used after calling centerInside");
      }
      centerCrop = true;
      return this;
    }

    /** Clear the center crop transformation flag, if set. */
    public Builder clearCenterCrop() {
      centerCrop = false;
      return this;
    }

    /**
     * Centers an image inside of the bounds specified by {@link #resize(int, int)}. This scales
     * the image so that both dimensions are equal to or less than the requested bounds.
     */
    public Builder centerInside() {
      if (centerCrop) {
        throw new IllegalStateException("Center inside can not be used after calling centerCrop");

View on GitHub (pinned to 626827cddb)

Solutions

  1. Use only one of centerCrop()/centerInside() per request; delete the conflicting call.
  2. If the builder is reused, call clearCenterInside() before centerCrop().
  3. Split shared builder setup so crop policy is decided in exactly one place.

Example fix

// before
RequestCreator c = picasso.load(url).resize(200, 200).centerInside();
c.centerCrop(); // throws

// after
RequestCreator c = picasso.load(url).resize(200, 200).centerInside();
// or, for fill-and-crop behavior:
RequestCreator c2 = picasso.load(url).resize(200, 200).centerCrop();
Defensive patterns

Strategy: validation

Validate before calling

// Decide the strategy once before building the request
boolean useCrop = /* single source of truth */;
RequestCreator c = picasso.load(url).resize(w, h);
if (useCrop) c.centerCrop(); else c.centerInside();

Prevention

When it happens

Trigger: Chaining .centerInside().centerCrop() or calling centerInside() earlier (e.g., in shared builder-setup code) and centerCrop() later on the same builder instance.

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

Related errors


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