{"record":{"id":"3e673b65c73dc778","repo":"alibaba/Sentinel","slug":"invalid-intervalunit","errorCode":null,"errorMessage":"Invalid intervalUnit: {}","messagePattern":"Invalid intervalUnit: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/GatewayFlowRuleEntity.java","lineNumber":81,"sourceCode":"    private Integer maxQueueingTimeoutMs;\n\n    private GatewayParamFlowItemEntity paramItem;\n\n    public static Long calIntervalSec(Long interval, Integer intervalUnit) {\n        switch (intervalUnit) {\n            case INTERVAL_UNIT_SECOND:\n                return interval;\n            case INTERVAL_UNIT_MINUTE:\n                return interval * 60;\n            case INTERVAL_UNIT_HOUR:\n                return interval * 60 * 60;\n            case INTERVAL_UNIT_DAY:\n                return interval * 60 * 60 * 24;\n            default:\n                break;\n        }\n\n        throw new IllegalArgumentException(\"Invalid intervalUnit: \" + intervalUnit);\n    }\n\n    public static Object[] parseIntervalSec(Long intervalSec) {\n        if (intervalSec % (60 * 60 * 24) == 0) {\n            return new Object[] {intervalSec / (60 * 60 * 24), INTERVAL_UNIT_DAY};\n        }\n\n        if (intervalSec % (60 * 60 ) == 0) {\n            return new Object[] {intervalSec / (60 * 60), INTERVAL_UNIT_HOUR};\n        }\n\n        if (intervalSec % 60 == 0) {\n            return new Object[] {intervalSec / 60, INTERVAL_UNIT_MINUTE};\n        }\n\n        return new Object[] {intervalSec, INTERVAL_UNIT_SECOND};\n    }\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/GatewayFlowRuleEntity.java#L63-L99","documentation":"GatewayFlowRuleEntity.getIntervalSec() (Sentinel dashboard gateway flow rule model) converts the rule's interval value plus intervalUnit (SECOND/MINUTE/HOUR/DAY constants) into seconds. If intervalUnit is not one of the four known constants it falls through the switch and throws IllegalArgumentException.","triggerScenarios":"Calling entity.getIntervalSec() (directly or during save/validation) on a GatewayFlowRuleEntity whose intervalUnit field is 0, null, or any value outside the INTERVAL_UNIT_* constants.","commonSituations":"A gateway flow rule JSON posted to the dashboard API missing the intervalUnit field (deserializes to 0), or frontend code that never populates the unit selector for API/parameter based gateway rules.","solutions":["Ensure the rule payload sets intervalUnit to a valid constant (0=second, 1=minute, 2=hour, 3=day per GatewayFlowRuleEntity definitions).","If constructing GatewayFlowRuleEntity programmatically, always call setIntervalUnit(...) with one of the INTERVAL_UNIT_* constants.","Validate intervalUnit range before calling getIntervalSec()/persisting the rule."],"exampleFix":"// before\nGatewayFlowRuleEntity e = new GatewayFlowRuleEntity();\ne.setInterval(2);\n// intervalUnit never set\nlong sec = e.getIntervalSec(); // throws\n\n// after\ne.setInterval(2);\ne.setIntervalUnit(GatewayFlowRuleEntity.INTERVAL_UNIT_MINUTE);\nlong sec = e.getIntervalSec(); // 120","handlingStrategy":"validation","validationCode":"private static final Set<Integer> VALID_UNITS = new HashSet<>(Arrays.asList(\n    GatewayFlowRuleEntity.INTERVAL_UNIT_SECOND,\n    GatewayFlowRuleEntity.INTERVAL_UNIT_MINUTE,\n    GatewayFlowRuleEntity.INTERVAL_UNIT_HOUR,\n    GatewayFlowRuleEntity.INTERVAL_UNIT_DAY));\n\nif (!VALID_UNITS.contains(entity.getIntervalUnit())) {\n    entity.setIntervalUnit(GatewayFlowRuleEntity.INTERVAL_UNIT_SECOND);\n}\nlong sec = entity.getIntervalSec();","typeGuard":"boolean isValidIntervalUnit(Integer unit) {\n    return unit != null && unit >= 0 && unit <= 3;\n}","tryCatchPattern":null,"preventionTips":["Make intervalUnit a required field with a default in your DTOs and frontend forms.","Add schema validation on gateway rule JSON before posting to the dashboard API."],"tags":["sentinel","gateway","dashboard","flow-rule","validation"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}