{"record":{"id":"c9def75f2cb4405e","repo":"didi/DoKit","slug":"invalid-shadow-size","errorCode":null,"errorMessage":"invalid shadow size","messagePattern":"invalid shadow size","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/ShadowUtils.java","lineNumber":264,"sourceCode":"            mAddPaddingForCorners = addPaddingForCorners;\n            invalidateSelf();\n        }\n\n        @Override\n        public void setAlpha(int alpha) {\n            super.setAlpha(alpha);\n            mCornerShadowPaint.setAlpha(alpha);\n            mEdgeShadowPaint.setAlpha(alpha);\n        }\n\n        @Override\n        protected void onBoundsChange(Rect bounds) {\n            mDirty = true;\n        }\n\n        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            }\n            if (mRawShadowSize == shadowSize && mRawMaxShadowSize == maxShadowSize) {\n                return;\n            }\n            mRawShadowSize = shadowSize;\n            mRawMaxShadowSize = maxShadowSize;\n            mShadowSize = Math.round(shadowSize * mShadowMultiplier);\n            mMaxShadowSize = maxShadowSize;\n            mDirty = true;\n            invalidateSelf();\n        }\n\n        @Override","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/ShadowUtils.java#L246-L282","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nshadowDrawable.setShadowSize(cornerRadius - elevation, maxRadius);\n\n// after\nshadowDrawable.setShadowSize(Math.max(0f, cornerRadius - elevation), Math.max(0f, maxRadius));","handlingStrategy":"validation","validationCode":"float safeShadow = Math.max(0f, shadowSize);\nfloat safeMax = Math.max(0f, maxShadowSize);\nif (safeMax < safeShadow) safeMax = safeShadow;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass computed view dimensions to shadow sizes before layout completes.","Define all shadow dimens with sane non-negative defaults for every qualifier."],"tags":["android","ui","drawable","validation"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}