alibaba/Sentinel · error · IllegalStateException
arraySet() is unavailable if countAndSum() has been called
Error message
arraySet() is unavailable if countAndSum() has been called
What it means
StatEntryFuncCountAndSum implements the count-and-sum strategy (an AtomicLong count plus an AtomicLong sum). arraySet(long... values) belongs to the array-slot strategy where each slot is assigned a value; calling it on a count-and-sum entry throws IllegalStateException because the entry's internal state (two scalars) cannot represent an array of slots.
Source
Thrown at sentinel-core/src/main/java/com/alibaba/csp/sentinel/eagleeye/StatEntryFunc.java:99
@Override
public void count(long count) {
this.count.add(count);
}
@Override
public void countAndSum(long count, long value) {
this.count.add(count);
this.value.add(value);
}
@Override
public void arrayAdd(long... values) {
throw new IllegalStateException("arrayAdd() is unavailable if countAndSum() has been called");
}
@Override
public void arraySet(long... values) {
throw new IllegalStateException("arraySet() is unavailable if countAndSum() has been called");
}
@Override
public void minMax(long candidate, String ref) {
throw new IllegalStateException("minMax() is unavailable if countAndSum() has been called");
}
@Override
public void batchAdd(long... values) {
throw new IllegalStateException("batchAdd() is unavailable if countAndSum() has been called");
}
@Override
public void strArray(String... values) {
throw new IllegalStateException("strArray() is unavailable if countAndSum() has been called");
}
}
View on GitHub (pinned to a3f40ba8e9)
Solutions
- Change the write call to countAndSum(count, value) (or count(count)) to match the entry type.
- Or change the entry creation to the array type if slot assignment is what you need.
- Add a unit test per metric name asserting the writer matches the configured stat type.
Example fix
// before entryFunc.arraySet(dailyTotals); // entry is count-and-sum -> throws // after entryFunc.countAndSum(1, delta);
Defensive patterns
Strategy: type-guard
Validate before calling
if (func.getStatType() == 2) { func.countAndSum(1, value); } else { func.arraySet(values); } Type guard
boolean isCountAndSum(StatEntryFunc f) { return f.getStatType() == 2; } Prevention
- Keep metric type and writer method adjacent in code/config so they change together.
- Avoid generic write-all recorders; use per-strategy recorder classes.
- Add a compile-time-ish check: assert strategy support in a unit test per metric.
When it happens
Trigger: Calling arraySet(values) on an entry whose func is StatEntryFuncCountAndSum — typically a reporting loop that was written for an arraySet-style metric but is applied to a countAndSum entry, or a config-driven metric definition whose type and writer disagree.
Common situations: Metric definitions live in configuration; the type says count_and_sum but the emitter code calls arraySet. Code reuse across metric modules with different entry types. Migration from array metrics to count/sum metrics where one call site was missed.
Related errors
- arrayAdd() is unavailable if countAndSum() has been called
- minMax() is unavailable if countAndSum() has been called
- batchAdd() is unavailable if countAndSum() has been called
- strArray() is unavailable if countAndSum() has been called
- count() is unavailable if minMax() has been called
AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14).
Data as JSON: /api/errors/f5ea0ec2ea091ab4.
Report an issue: GitHub.