{"record":{"id":"29760aeb0307879e","repo":"apache/dubbo","slug":"illegal-eviction-factor-value-evictionfactor","errorCode":null,"errorMessage":"Illegal eviction factor value:${evictionFactor}","messagePattern":"Illegal eviction factor value:(.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/LFUCache.java","lineNumber":56,"sourceCode":"        this(DEFAULT_INITIAL_CAPACITY, DEFAULT_EVICTION_FACTOR);\n    }\n\n    /**\n     * Constructs and initializes cache with specified capacity and eviction\n     * factor. Unacceptable parameter values followed with\n     * {@link IllegalArgumentException}.\n     *\n     * @param maxCapacity    cache max capacity\n     * @param evictionFactor cache proceedEviction factor\n     */\n    @SuppressWarnings(\"unchecked\")\n    public LFUCache(final int maxCapacity, final float evictionFactor) {\n        if (maxCapacity <= 0) {\n            throw new IllegalArgumentException(\"Illegal initial capacity: \" + maxCapacity);\n        }\n        boolean factorInRange = evictionFactor <= 1 && evictionFactor > 0;\n        if (!factorInRange || Float.isNaN(evictionFactor)) {\n            throw new IllegalArgumentException(\"Illegal eviction factor value:\" + evictionFactor);\n        }\n        this.capacity = maxCapacity;\n        this.evictionCount = (int) (capacity * evictionFactor);\n        this.map = new HashMap<>();\n        this.freqTable = new CacheDeque[capacity + 1];\n        for (int i = 0; i <= capacity; i++) {\n            freqTable[i] = new CacheDeque<>();\n        }\n        for (int i = 0; i < capacity; i++) {\n            freqTable[i].nextDeque = freqTable[i + 1];\n        }\n        freqTable[capacity].nextDeque = freqTable[capacity];\n    }\n\n    public int getCapacity() {\n        return capacity;\n    }\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LFUCache.java#L38-L74","documentation":"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.","triggerScenarios":"Instantiating new LFUCache(capacity, factor) where factor is <= 0, > 1, or Float.NaN; e.g. reading the factor from config without bounds checking.","commonSituations":"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).","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"],"exampleFix":"// before\nnew LFUCache<>(100, 80f);   // 80 > 1, rejected\n// after\nnew LFUCache<>(100, 0.8f);","handlingStrategy":"validation","validationCode":"float f = configuredFactor;\nif (!(f > 0 && f <= 1) || Float.isNaN(f)) throw new IllegalArgumentException(\"bad factor: \" + f);\nnew LFUCache<>(100, f);","typeGuard":"static boolean validFactor(float f) { return !Float.isNaN(f) && f > 0 && f <= 1; }","tryCatchPattern":"try { new LFUCache<>(cap, factor); }\ncatch (IllegalArgumentException e) { /* factor out of (0,1]; default to 0.8f */ }","preventionTips":["Express eviction factor as a fraction, not a percentage","Validate config values in a dedicated validator before object construction"],"tags":["cache","config","validation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}