alibaba/Sentinel · error · IllegalStateException

countAndSum() is unavailable if minMax() has been called

Error message

countAndSum() is unavailable if minMax() has been called

What it means

StatEntryFuncMinMax stores only max/min ValueRef pairs; it cannot accumulate a count or a sum, so countAndSum(long count, long value) throws IllegalStateException. The supported write method for this strategy is exclusively minMax(candidate, ref).

Source

Thrown at sentinel-core/src/main/java/com/alibaba/csp/sentinel/eagleeye/StatEntryFunc.java:159

    public Object[] getValues() {
        ValueRef lmax = max.get();
        ValueRef lmin = min.get();
        return new Object[] {lmax.value, lmax.ref, lmin.value, lmin.ref};
    }

    @Override
    public int getStatType() {
        return 4;
    }

    @Override
    public void count(long count) {
        throw new IllegalStateException("count() is unavailable if minMax() has been called");
    }

    @Override
    public void countAndSum(long count, long value) {
        throw new IllegalStateException("countAndSum() is unavailable if minMax() has been called");
    }

    @Override
    public void arrayAdd(long... values) {
        throw new IllegalStateException("arrayAdd() is unavailable if minMax() has been called");
    }

    @Override
    public void arraySet(long... values) {
        throw new IllegalStateException("arraySet() is unavailable if minMax() has been called");
    }

    @Override
    public void batchAdd(long... values) {
        throw new IllegalStateException("batchAdd() is unavailable if minMax() has been called");
    }

    @Override

View on GitHub (pinned to a3f40ba8e9)

Solutions

  1. Call minMax(candidate, ref) on min/max entries; put count/sum in a second entry.
  2. Restructure the metric as two entries sharing the same keys so the output row still reads coherently.
  3. Add a startup assertion that the configured entry type matches the writer method.

Example fix

// before
func.countAndSum(1, elapsed); // minMax entry -> throws

// after
minMaxFunc.minMax(elapsed, resource);
countFunc.countAndSum(1, elapsed);
Defensive patterns

Strategy: type-guard

Validate before calling

if (func.getStatType() == 4) {
    func.minMax(value, ref);
} else {
    func.countAndSum(1, value);
}

Type guard

boolean isMinMax(StatEntryFunc f) { return f.getStatType() == 4; }

Prevention

When it happens

Trigger: Calling countAndSum(c, v) on an entry whose func is StatEntryFuncMinMax — e.g. latency-tracking code that tries to record both totals and extremes on one entry, or a writer selected by config that no longer matches the entry type.

Common situations: Teams want avg+min+max in one row and assume one entry can do all of it. Metric type changed in configuration. Copy-pasted aggregation code between different stat entries.

Related errors


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