{"record":{"id":"e169a87cca9d2d9c","repo":"alibaba/Sentinel","slug":"invalid-degraderule","errorCode":null,"errorMessage":"Invalid DegradeRule: ","messagePattern":"Invalid DegradeRule: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/circuitbreaker/AbstractCircuitBreaker.java","lineNumber":51,"sourceCode":"public abstract class AbstractCircuitBreaker implements CircuitBreaker {\n    protected static final double MAX_RATIO = 1.0d;\n\n    protected final DegradeRule rule;\n    protected final int recoveryTimeoutMs;\n\n    private final EventObserverRegistry observerRegistry;\n\n    protected final AtomicReference<State> currentState = new AtomicReference<>(State.CLOSED);\n    protected volatile long nextRetryTimestamp;\n\n    public AbstractCircuitBreaker(DegradeRule rule) {\n        this(rule, EventObserverRegistry.getInstance());\n    }\n\n    AbstractCircuitBreaker(DegradeRule rule, EventObserverRegistry observerRegistry) {\n        AssertUtil.notNull(observerRegistry, \"observerRegistry cannot be null\");\n        if (!DegradeRuleManager.isValidRule(rule)) {\n            throw new IllegalArgumentException(\"Invalid DegradeRule: \" + rule);\n        }\n        this.observerRegistry = observerRegistry;\n        this.rule = rule;\n        this.recoveryTimeoutMs = rule.getTimeWindow() * 1000;\n    }\n\n    @Override\n    public DegradeRule getRule() {\n        return rule;\n    }\n\n    @Override\n    public State currentState() {\n        return currentState.get();\n    }\n\n    @Override\n    public boolean tryPass(Context context) {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/block/degrade/circuitbreaker/AbstractCircuitBreaker.java#L33-L69","documentation":"AbstractCircuitBreaker (base of CircuitBreakerRule and ResponseTimeCircuitBreaker) validates the DegradeRule via DegradeRuleManager.isValidRule(rule) before building the breaker. If the rule fails validation (null rule, or invalid grade/timeWindow/count combination) it throws IllegalArgumentException with the rule toString appended.","triggerScenarios":"new CircuitBreakerRule(degradeRule) or new ResponseTimeCircuitBreaker(degradeRule) where degradeRule is null, has timeWindow <= 0, or a count/grade combination DegradeRuleManager rejects; also triggered when registering an invalid rule via DegradeRuleManager.loadRules with circuit breaker types.","commonSituations":"Loading degrade rules from a dashboard or datasource where timeWindow was never set (defaults to 0), mixing old rule grades not supported by the circuit breaker strategy, or passing a rule whose count is negative.","solutions":["Inspect the DegradeRule in the error message: ensure it is non-null and has grade, count, and timeWindow (seconds) set to valid values.","Run DegradeRuleManager.isValidRule(rule) yourself before constructing a circuit breaker to get field-level errors.","Fix the rule source (dashboard form / Nacos/Apollo config) — usually timeWindow must be > 0 and statIntervalMs/count within allowed bounds."],"exampleFix":"// before\nDegradeRule rule = new DegradeRule(\"foo\");\nrule.setGrade(RuleConstant.DEGRADE_GRADE_RT);\n// timeWindow never set (0) -> invalid\nnew ResponseTimeCircuitBreaker(rule);\n\n// after\nDegradeRule rule = new DegradeRule(\"foo\");\nrule.setGrade(RuleConstant.DEGRADE_GRADE_RT);\nrule.setCount(10);          // RT threshold ms\nrule.setTimeWindow(10);     // recovery window, seconds\nnew ResponseTimeCircuitBreaker(rule);","handlingStrategy":"validation","validationCode":"if (rule == null || !DegradeRuleManager.isValidRule(rule)) {\n    // reject with details before building the circuit breaker\n    throw new IllegalArgumentException(\"Invalid DegradeRule: \" + rule);\n}\nCircuitBreaker cb = rule.getGrade() == RuleConstant.DEGRADE_GRADE_RT\n    ? new ResponseTimeCircuitBreaker(rule)\n    : new CircuitBreakerRule(rule);","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) {\n    RecordLog.warn(\"Rejected invalid degrade rule \" + rule, e);\n    // skip this rule, keep processing the rest of the rule list\n}","preventionTips":["Validate rules at load time (isValidRule) and log the offending rule instead of failing the whole rule batch.","Enforce timeWindow > 0 and sane count/statIntervalMs in dashboard forms and datasource schemas."],"tags":["sentinel","circuit-breaker","degrade-rule","validation"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}