Skip to content

Commit 7e472fa

Browse files
committed
Fix NullPointerException in ASMCacheManager.getInstance()
- Add null/empty validation for cacheDirectory key in ConcurrentHashMap.computeIfAbsent() - ConcurrentHashMap does not allow null keys, causing NPE when cacheDir is null - Use default cache directory if provided config has null/empty directory - Add logging for null cache directory detection Resolves: java.lang.NullPointerException at ConcurrentHashMap.putVal in createCacheManager
1 parent da42aa1 commit 7e472fa

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

warmup-core/src/main/java/io/warmup/framework/cache/ASMCacheManager.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ public static ASMCacheManager getInstance() {
117117
// return customInstance;
118118
// }
119119
public static ASMCacheManager getInstance(CacheConfig config) {
120-
String key = config.getCacheDirectory(); // <-- Clave basada en directorio
121-
// Opcional: String key = config.getCacheDirectory() + "|" + config.getMaxCacheAge();
122-
return instances.computeIfAbsent(key, k -> new ASMCacheManager(config));
120+
// FIX: Verificar que la clave no sea null para evitar NullPointerException en ConcurrentHashMap
121+
String cacheDir = config.getCacheDirectory();
122+
if (cacheDir == null || cacheDir.isEmpty()) {
123+
cacheDir = CacheConfig.defaultConfig().getCacheDirectory();
124+
log.log(Level.WARNING, "Cache directory was null/empty, using default: {0}", cacheDir);
125+
}
126+
return instances.computeIfAbsent(cacheDir, k -> new ASMCacheManager(config));
123127
}
124128

125129
/**

0 commit comments

Comments
 (0)