{"record":{"id":"f01353bccfe67f8c","repo":"TheAlgorithms/Java","slug":"eviction-strategy-must-not-be-null-f01353","errorCode":null,"errorMessage":"Eviction strategy must not be null","messagePattern":"Eviction strategy must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/datastructures/caches/LIFOCache.java","lineNumber":557,"sourceCode":"        /**\n         * Builds and returns a new {@link LIFOCache} instance with the configured parameters.\n         *\n         * @return a fully configured {@code LIFOCache} instance\n         */\n        public LIFOCache<K, V> build() {\n            return new LIFOCache<>(this);\n        }\n\n        /**\n         * Sets the eviction strategy used to determine when to clean up expired entries.\n         *\n         * @param strategy an {@link EvictionStrategy} implementation; must not be {@code null}\n         * @return this builder instance\n         * @throws IllegalArgumentException if {@code strategy} is {@code null}\n         */\n        public Builder<K, V> evictionStrategy(EvictionStrategy<K, V> strategy) {\n            if (strategy == null) {\n                throw new IllegalArgumentException(\"Eviction strategy must not be null\");\n            }\n            this.evictionStrategy = strategy;\n            return this;\n        }\n    }\n}\n","sourceCodeStart":539,"sourceCodeEnd":564,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/datastructures/caches/LIFOCache.java#L539-L564","documentation":"Thrown by LIFOCache.Builder.evictionStrategy(EvictionStrategy) when the strategy is null. The strategy's onAccess is called on every get/put; a null would NPE on every cache operation. The builder defaults to ImmediateEvictionStrategy, so this guard only fires when a caller explicitly passes null.","triggerScenarios":"builder.evictionStrategy(null); conditional wiring returning null in some branch; DI misconfiguration.","commonSituations":"Strategy selection by enum with a case returning null; refactoring leaving a null branch; tests resetting the strategy.","solutions":["Omit evictionStrategy() to keep the default ImmediateEvictionStrategy.","Provide a concrete strategy or a no-op: cache -> 0.","Ensure your strategy-selection helper never returns null."],"exampleFix":"// before\nbuilder.evictionStrategy(selectStrategy(mode));\n// after\nEvictionStrategy<K,V> s = selectStrategy(mode);\nif (s != null) builder.evictionStrategy(s);","handlingStrategy":"validation","validationCode":"EvictionStrategy<K, V> s = selectStrategy(mode);\nif (s != null) builder.evictionStrategy(s);","typeGuard":"static <K, V> boolean isUsableStrategy(EvictionStrategy<K, V> s) {\n    return s != null;\n}","tryCatchPattern":null,"preventionTips":["Omit evictionStrategy() to keep the default ImmediateEvictionStrategy.","Ensure strategy-selection helpers return a no-op instead of null.","Cover all enum branches when selecting a strategy."],"tags":["java","lifo-cache","builder","null-check","eviction-strategy","argument-validation","cache"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}