didi/DoKit · error · IllegalArgumentException
invalid shadow size
Error message
invalid shadow size
What it means
Thrown by setShadowSize(float, float) inside ShadowUtils' shadow drawable when either the shadow size or the max shadow size is negative. The method then rounds both values to even integers and clamps shadowSize to maxShadowSize, so the only invalid input is a negative argument. This mirrors the validation in AndroidX CardView's RoundRectDrawableWithShadow.
Source
Thrown at Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/ShadowUtils.java:264
mAddPaddingForCorners = addPaddingForCorners;
invalidateSelf();
}
@Override
public void setAlpha(int alpha) {
super.setAlpha(alpha);
mCornerShadowPaint.setAlpha(alpha);
mEdgeShadowPaint.setAlpha(alpha);
}
@Override
protected void onBoundsChange(Rect bounds) {
mDirty = true;
}
void setShadowSize(float shadowSize, float maxShadowSize) {
if (shadowSize < 0 || maxShadowSize < 0) {
throw new IllegalArgumentException("invalid shadow size");
}
shadowSize = toEven(shadowSize);
maxShadowSize = toEven(maxShadowSize);
if (shadowSize > maxShadowSize) {
shadowSize = maxShadowSize;
}
if (mRawShadowSize == shadowSize && mRawMaxShadowSize == maxShadowSize) {
return;
}
mRawShadowSize = shadowSize;
mRawMaxShadowSize = maxShadowSize;
mShadowSize = Math.round(shadowSize * mShadowMultiplier);
mMaxShadowSize = maxShadowSize;
mDirty = true;
invalidateSelf();
}
@OverrideView on GitHub (pinned to 626827cddb)
Solutions
- Clamp inputs before calling: use Math.max(0, size) for both shadowSize and maxShadowSize.
- Check the dimens/dimens.xml entries that supply the shadow sizes (missing qualifiers often yield wrong values).
- Guard call sites that compute sizes from un-laid-out views (width/height are 0 or negative before onLayout).
Example fix
// before shadowDrawable.setShadowSize(cornerRadius - elevation, maxRadius); // after shadowDrawable.setShadowSize(Math.max(0f, cornerRadius - elevation), Math.max(0f, maxRadius));
Defensive patterns
Strategy: validation
Validate before calling
float safeShadow = Math.max(0f, shadowSize); float safeMax = Math.max(0f, maxShadowSize); if (safeMax < safeShadow) safeMax = safeShadow;
Prevention
- Never pass computed view dimensions to shadow sizes before layout completes.
- Define all shadow dimens with sane non-negative defaults for every qualifier.
When it happens
Trigger: Constructing the shadow drawable or calling setShadowSize() / setMaxShadowSize() with a negative value, e.g. dimens that resolve to a negative number, or computing shadow size as a difference like (smallerDimen - largerDimen) that goes below zero.
Common situations: A dp-to-pixel dimension missing on some build flavors resolves to a negative fallback; a size computed from view measurements before layout returns a negative number; copy-pasted CardView shadow code fed with computed sizes.
Related errors
- Use setColor method of Paint class to specify line color. Do
- Use setStrokeWidth method of Paint class to specify line siz
- maxStoredHeapDumps must be at least 1
- Set circle needn't set radius.
- input must be shorter than or equal to the number of spaces:
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/c9def75f2cb4405e.
Report an issue: GitHub.