didi/DoKit · error · IllegalStateException
onlyScaleDown can not be applied without resize
Error message
onlyScaleDown can not be applied without resize
What it means
Thrown by Request.Builder.onlyScaleDown() when neither targetWidth nor targetHeight has been set via resize(). onlyScaleDown modifies an existing resize target (skip scaling up beyond the original size); without a target there is nothing to compare against, so it is rejected.
Source
Thrown at Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Request.java:366
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");
}
onlyScaleDown = true;
return this;
}
/** Clear the onlyScaleUp flag, if set. **/
public Builder clearOnlyScaleDown() {
onlyScaleDown = false;
return this;
}
/** Rotate the image by the specified degrees. */
public Builder rotate(float degrees) {
rotationDegrees = degrees;
return this;
}
/** Rotate the image by the specified degrees around a pivot point. */View on GitHub (pinned to 626827cddb)
Solutions
- Call resize(w, h) (at least one positive dimension) before onlyScaleDown().
- If you want 'fit the view but never upscale', use .fit().centerInside() or resize to view dims then onlyScaleDown().
- Audit builder pipelines that call clearResize() — onlyScaleDown becomes invalid after it.
Example fix
// before picasso.load(url).onlyScaleDown().into(imageView); // no resize // after picasso.load(url).resize(imageView.getWidth(), 0).onlyScaleDown().into(imageView);
Defensive patterns
Strategy: validation
Validate before calling
if (targetWidth > 0 || targetHeight > 0) {
builder.resize(targetWidth, targetHeight).onlyScaleDown();
} Prevention
- Order matters: resize() must precede onlyScaleDown().
- onlyScaleDown() becomes invalid again after clearResize().
When it happens
Trigger: Calling .onlyScaleDown() before any .resize(w, h) on the same builder, or after clearResize().
Common situations: Copying a chain like load(url).onlyScaleDown().resize(...) in the wrong order; calling clearResize() in shared code and then onlyScaleDown(); forgetting resize when switching from fit() to explicit sizing.
Related errors
- Center crop requires calling resize with positive width and
- Center inside requires calling resize with positive width an
- Width must be positive number or 0.
- Height must be positive number or 0.
- Center crop can not be used after calling centerInside
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/fcb641be2743725a.
Report an issue: GitHub.