Skip to content

Commit c6f37ef

Browse files
committed
Fix NullPointerException in ASMCacheManager constructor and getInstance()
- Add null check for config parameter in getInstance() to prevent NPE before accessing getCacheDirectory() - Add null check for config parameter in constructor before accessing config fields - Add null/empty validation for cacheDirectory in constructor before calling Paths.get() - Use direct field access (config.cacheDirectory) instead of getter after null check - Add logging when null config or cache directory is detected This fixes the ConcurrentHashMap.putVal NPE that was occurring during ContainerCoordinator.createCacheManager() initialization. Resolves: java.lang.NullPointerException at ConcurrentHashMap.putVal in createCacheManager
1 parent 7e472fa commit c6f37ef

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,22 @@ private static class Holder {
4646
private static final Object LOCK = new Object();
4747

4848
private ASMCacheManager(CacheConfig config) {
49+
// FIX: Verificar que config no sea null para evitar NullPointerException
50+
if (config == null) {
51+
log.log(Level.WARNING, "CacheConfig was null in constructor, using default config");
52+
config = CacheConfig.defaultConfig();
53+
}
54+
4955
this.config = config;
50-
this.cacheDirectory = Paths.get(config.cacheDirectory);
56+
57+
// FIX: Verificar que cacheDirectory no sea null
58+
String cacheDir = config.cacheDirectory;
59+
if (cacheDir == null || cacheDir.isEmpty()) {
60+
cacheDir = CacheConfig.defaultConfig().cacheDirectory;
61+
log.log(Level.WARNING, "Cache directory was null/empty in constructor, using default: {0}", cacheDir);
62+
}
63+
64+
this.cacheDirectory = Paths.get(cacheDir);
5165
this.memoryCache = new LRUCache<>(config.maxMemoryCacheSize);
5266
this.isTestEnvironment = detectTestEnvironment();
5367
this.diskExecutor = Executors.newFixedThreadPool(
@@ -117,6 +131,12 @@ public static ASMCacheManager getInstance() {
117131
// return customInstance;
118132
// }
119133
public static ASMCacheManager getInstance(CacheConfig config) {
134+
// FIX: Verificar que config no sea null para evitar NullPointerException
135+
if (config == null) {
136+
log.log(Level.WARNING, "CacheConfig was null, using default config");
137+
config = CacheConfig.defaultConfig();
138+
}
139+
120140
// FIX: Verificar que la clave no sea null para evitar NullPointerException en ConcurrentHashMap
121141
String cacheDir = config.getCacheDirectory();
122142
if (cacheDir == null || cacheDir.isEmpty()) {

0 commit comments

Comments
 (0)