{"record":{"id":"982655211a31133d","repo":"material-components/material-components-android","slug":"invalid-shadow-size","errorCode":null,"errorMessage":"invalid shadow size","messagePattern":"invalid shadow size","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/shadow/ShadowDrawableWrapper.java","lineNumber":127,"sourceCode":"    this.addPaddingForCorners = addPaddingForCorners;\n    invalidateSelf();\n  }\n\n  @Override\n  public void setAlpha(int alpha) {\n    super.setAlpha(alpha);\n    cornerShadowPaint.setAlpha(alpha);\n    edgeShadowPaint.setAlpha(alpha);\n  }\n\n  @Override\n  protected void onBoundsChange(Rect bounds) {\n    dirty = true;\n  }\n\n  public void setShadowSize(float shadowSize, float maxShadowSize) {\n    if (shadowSize < 0 || maxShadowSize < 0) {\n      throw new IllegalArgumentException(\"invalid shadow size\");\n    }\n    shadowSize = toEven(shadowSize);\n    maxShadowSize = toEven(maxShadowSize);\n    if (shadowSize > maxShadowSize) {\n      shadowSize = maxShadowSize;\n      if (!printedShadowClipWarning) {\n        printedShadowClipWarning = true;\n      }\n    }\n    if (rawShadowSize == shadowSize && rawMaxShadowSize == maxShadowSize) {\n      return;\n    }\n    rawShadowSize = shadowSize;\n    rawMaxShadowSize = maxShadowSize;\n    this.shadowSize = Math.round(shadowSize * SHADOW_MULTIPLIER);\n    this.maxShadowSize = maxShadowSize;\n    dirty = true;\n    invalidateSelf();","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/shadow/ShadowDrawableWrapper.java#L109-L145","documentation":"ShadowDrawableWrapper.setShadowSize(float, float) throws IllegalArgumentException when either the shadow size or the max shadow size is negative. Sizes are rounded to even pixel values for symmetric shadow rendering; negative dimensions would invert the shadow geometry, so they are rejected immediately.","triggerScenarios":"Calling setShadowSize() (directly or via CardView-style elevation helpers) with a negative dp-to-px conversion — e.g. multiplying by a negative density, passing -elevation, or an arithmetic bug that yields < 0.","commonSituations":"Computing shadow size from a difference like (margin - padding) that can go negative on dense/small screens; interpolating shadow size toward 0 and overshooting slightly below zero; passing raw negative float state values (e.g. scroll offset) as elevation.","solutions":["Clamp values before the call: setShadowSize(Math.max(0, shadowSize), Math.max(0, maxShadowSize)).","Fix the arithmetic producing the negative value (check dp * density math and interpolation bounds).","If animating shadow size, animate within [0, target] and use an interpolator/clamp that cannot overshoot below 0."],"exampleFix":"// before\nwrapper.setShadowSize(currentElevation - removedElevation, maxShadow);\n\n// after\nwrapper.setShadowSize(Math.max(0f, currentElevation - removedElevation), Math.max(0f, maxShadow));","handlingStrategy":"validation","validationCode":"float clamped = Math.max(0f, computedShadowSize);\nfloat clampedMax = Math.max(clamped, Math.max(0f, computedMaxShadowSize));\nwrapper.setShadowSize(clamped, clampedMax);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always clamp interpolated elevation to [0, max] with an end-of-animation clamp.","Unit-test size computations at density extremes (small/xxlarge screens)."],"tags":["android","material-components","shadow","validation","animation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}