didi/DoKit · error · IllegalStateException

Center inside can not be used after calling centerCrop

Error message

Center inside can not be used after calling centerCrop

What it means

Thrown by Request.Builder.centerInside() when centerCrop() was already called on the same builder. It is the mirror of the centerCrop() guard: the two scaling strategies are mutually exclusive and Picasso enforces this as soon as the second one is set.

Source

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

        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");
      }
      centerInside = true;
      return this;
    }

    /** Clear the center inside transformation flag, if set. */
    public Builder clearCenterInside() {
      centerInside = false;
      return this;
    }

    /**
     * Only resize an image if the original image size is bigger than the target size
     * specified by {@link #resize(int, int)}.
     */
    public Builder onlyScaleDown() {
      if (targetHeight == 0 && targetWidth == 0) {
        throw new IllegalStateException("onlyScaleDown can not be applied without resize");

View on GitHub (pinned to 626827cddb)

Solutions

  1. Pick one strategy per request and remove the other call.
  2. Call clearCenterCrop() before centerInside() if the builder legitimately carries a stale flag.
  3. Make the crop strategy an explicit parameter of your helper method so both branches can never run.

Example fix

// before
public RequestCreator thumb(String url) {
  return picasso.load(url).resize(100, 100).centerCrop().centerInside();
}

// after
public RequestCreator thumb(String url, boolean crop) {
  RequestCreator c = picasso.load(url).resize(100, 100);
  return crop ? c.centerCrop() : c.centerInside();
}
Defensive patterns

Strategy: validation

Validate before calling

if (!builderHasCenterCrop) { builder.centerInside(); } // guard shared-builder paths

Prevention

When it happens

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

Common situations: Common builder template that applies centerCrop(), then a list item path adds centerInside(); merging code from two examples; conditional logic that adds both branches.

Related errors


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