apache/dubbo · error · IllegalArgumentException
Illegal eviction factor value:${evictionFactor}
Error message
Illegal eviction factor value:${evictionFactor} What it means
LFUCache constructor validates that evictionFactor is in the exclusive-open range (0, 1] and not NaN. Out-of-range or NaN factors are rejected because they determine how many entries are evicted when capacity is exceeded.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/LFUCache.java:56
this(DEFAULT_INITIAL_CAPACITY, DEFAULT_EVICTION_FACTOR);
}
/**
* Constructs and initializes cache with specified capacity and eviction
* factor. Unacceptable parameter values followed with
* {@link IllegalArgumentException}.
*
* @param maxCapacity cache max capacity
* @param evictionFactor cache proceedEviction factor
*/
@SuppressWarnings("unchecked")
public LFUCache(final int maxCapacity, final float evictionFactor) {
if (maxCapacity <= 0) {
throw new IllegalArgumentException("Illegal initial capacity: " + maxCapacity);
}
boolean factorInRange = evictionFactor <= 1 && evictionFactor > 0;
if (!factorInRange || Float.isNaN(evictionFactor)) {
throw new IllegalArgumentException("Illegal eviction factor value:" + evictionFactor);
}
this.capacity = maxCapacity;
this.evictionCount = (int) (capacity * evictionFactor);
this.map = new HashMap<>();
this.freqTable = new CacheDeque[capacity + 1];
for (int i = 0; i <= capacity; i++) {
freqTable[i] = new CacheDeque<>();
}
for (int i = 0; i < capacity; i++) {
freqTable[i].nextDeque = freqTable[i + 1];
}
freqTable[capacity].nextDeque = freqTable[capacity];
}
public int getCapacity() {
return capacity;
}
View on GitHub (pinned to 3a3043227f)
Solutions
- Express the eviction factor as a fraction strictly greater than 0 and <= 1
- Validate/clamp the config value at load time before constructing the cache
- Default to a safe value like 0.8 when the property is missing
Example fix
// before new LFUCache<>(100, 80f); // 80 > 1, rejected // after new LFUCache<>(100, 0.8f);
Defensive patterns
Strategy: validation
Validate before calling
float f = configuredFactor;
if (!(f > 0 && f <= 1) || Float.isNaN(f)) throw new IllegalArgumentException("bad factor: " + f);
new LFUCache<>(100, f); Type guard
static boolean validFactor(float f) { return !Float.isNaN(f) && f > 0 && f <= 1; } Try / catch
try { new LFUCache<>(cap, factor); }
catch (IllegalArgumentException e) { /* factor out of (0,1]; default to 0.8f */ } Prevention
- Express eviction factor as a fraction, not a percentage
- Validate config values in a dedicated validator before object construction
When it happens
Trigger: Instantiating new LFUCache(capacity, factor) where factor is <= 0, > 1, or Float.NaN; e.g. reading the factor from config without bounds checking.
Common situations: Eviction-factor config property mis-typed (e.g. 20 instead of 0.20); division producing 0 or NaN; copy-paste from a percentage (80) instead of a fraction (0.8).
Related errors
- Illegal initial capacity: ${maxCapacity}
- Invalid configurator rule, please specify at least one param
- service field in configuration is null.
- Illegal affinity rule!
- Illegal route rule!
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/29760aeb0307879e.
Report an issue: GitHub.