{"record":{"id":"f95c3fa2680b4ccd","repo":"didi/DoKit","slug":"set-circle-needn-t-set-radius","errorCode":null,"errorMessage":"Set circle needn't set radius.","messagePattern":"Set circle needn't set radius\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/ShadowUtils.java","lineNumber":78,"sourceCode":"        private static final int SHADOW_COLOR_DEFAULT = 0x44000000;\n        private static final int SHADOW_SIZE          = UtilsBridge.dp2px(8);\n\n        private float   mShadowRadius         = -1;\n        private float   mShadowSizeNormal     = -1;\n        private float   mShadowSizePressed    = -1;\n        private float   mShadowMaxSizeNormal  = -1;\n        private float   mShadowMaxSizePressed = -1;\n        private int     mShadowColorNormal    = SHADOW_COLOR_DEFAULT;\n        private int     mShadowColorPressed   = SHADOW_COLOR_DEFAULT;\n        private boolean isCircle              = false;\n\n        public Config() {\n        }\n\n        public Config setShadowRadius(float radius) {\n            this.mShadowRadius = radius;\n            if (isCircle) {\n                throw new IllegalArgumentException(\"Set circle needn't set radius.\");\n            }\n            return this;\n        }\n\n        public Config setCircle() {\n            isCircle = true;\n            if (mShadowRadius != -1) {\n                throw new IllegalArgumentException(\"Set circle needn't set radius.\");\n            }\n            return this;\n        }\n\n        public Config setShadowSize(int size) {\n            return setShadowSize(size, size);\n        }\n\n        public Config setShadowSize(int sizeNormal, int sizePressed) {\n            this.mShadowSizeNormal = sizeNormal;","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/ShadowUtils.java#L60-L96","documentation":"ShadowUtils.Config.setShadowRadius throws if the builder has already been marked circular (isCircle == true). Circular shadows derive their radius from the view's circle dimensions, so an explicit radius is contradictory and rejected. Note the radius is assigned before the check, but the throw still aborts the builder chain.","triggerScenarios":"Calling config.setCircle() first and then setShadowRadius(10) on the same Config instance; copy-pasted builder chains where both options survive a refactor.","commonSituations":"Refactoring a rounded-rect shadow into a circular one and forgetting to delete the radius line; conditional builder code that applies radius in one branch and circle in another but both execute.","solutions":["Remove the setShadowRadius call for circular views; the radius comes from the circle itself.","Make the choice exclusive in your code: if (isCircular) cfg.setCircle() else cfg.setShadowRadius(r).","Audit builder chains after converting shapes between circle and rect."],"exampleFix":"// before\nnew ShadowUtils.Config().setCircle().setShadowRadius(8f).apply(v); // throws\n\n// after\nnew ShadowUtils.Config().setCircle().apply(v); // radius implicit from circle","handlingStrategy":"validation","validationCode":"if (isCircular) cfg.setCircle(); else cfg.setShadowRadius(radius); // never both","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Decide shape before building the Config; circle and radius are mutually exclusive.","Delete radius lines when converting a view to circular."],"tags":["ui","builder","shadow","validation"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}