alibaba/Sentinel · error · IllegalArgumentException

Invalid intervalUnit

Error message

Invalid intervalUnit: {}

What it means

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.

Solutions

  1. Ensure the rule payload sets intervalUnit to a valid constant (0=second, 1=minute, 2=hour, 3=day per GatewayFlowRuleEntity definitions).
  2. If constructing GatewayFlowRuleEntity programmatically, always call setIntervalUnit(...) with one of the INTERVAL_UNIT_* constants.
  3. Validate intervalUnit range before calling getIntervalSec()/persisting the rule.

Example fix

// before
GatewayFlowRuleEntity e = new GatewayFlowRuleEntity();
e.setInterval(2);
// intervalUnit never set
long sec = e.getIntervalSec(); // throws

// after
e.setInterval(2);
e.setIntervalUnit(GatewayFlowRuleEntity.INTERVAL_UNIT_MINUTE);
long sec = e.getIntervalSec(); // 120
Defensive patterns

Strategy: validation

Validate before calling

private static final Set<Integer> VALID_UNITS = new HashSet<>(Arrays.asList(
    GatewayFlowRuleEntity.INTERVAL_UNIT_SECOND,
    GatewayFlowRuleEntity.INTERVAL_UNIT_MINUTE,
    GatewayFlowRuleEntity.INTERVAL_UNIT_HOUR,
    GatewayFlowRuleEntity.INTERVAL_UNIT_DAY));

if (!VALID_UNITS.contains(entity.getIntervalUnit())) {
    entity.setIntervalUnit(GatewayFlowRuleEntity.INTERVAL_UNIT_SECOND);
}
long sec = entity.getIntervalSec();

Type guard

boolean isValidIntervalUnit(Integer unit) {
    return unit != null && unit >= 0 && unit <= 3;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14). Data as JSON: /api/errors/3e673b65c73dc778. Report an issue: GitHub.

Appendix: source

Thrown at sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/gateway/GatewayFlowRuleEntity.java:81

    private Integer maxQueueingTimeoutMs;

    private GatewayParamFlowItemEntity paramItem;

    public static Long calIntervalSec(Long interval, Integer intervalUnit) {
        switch (intervalUnit) {
            case INTERVAL_UNIT_SECOND:
                return interval;
            case INTERVAL_UNIT_MINUTE:
                return interval * 60;
            case INTERVAL_UNIT_HOUR:
                return interval * 60 * 60;
            case INTERVAL_UNIT_DAY:
                return interval * 60 * 60 * 24;
            default:
                break;
        }

        throw new IllegalArgumentException("Invalid intervalUnit: " + intervalUnit);
    }

    public static Object[] parseIntervalSec(Long intervalSec) {
        if (intervalSec % (60 * 60 * 24) == 0) {
            return new Object[] {intervalSec / (60 * 60 * 24), INTERVAL_UNIT_DAY};
        }

        if (intervalSec % (60 * 60 ) == 0) {
            return new Object[] {intervalSec / (60 * 60), INTERVAL_UNIT_HOUR};
        }

        if (intervalSec % 60 == 0) {
            return new Object[] {intervalSec / 60, INTERVAL_UNIT_MINUTE};
        }

        return new Object[] {intervalSec, INTERVAL_UNIT_SECOND};
    }

View on GitHub (pinned to a3f40ba8e9)