Skip to content

Commit 4a307a2

Browse files
committed
Fix NullPointerException in cache pre-warming
- Add null/empty validation for className in ContainerCoordinator.preWarmCriticalCaches() - Add null checks in AsmCoreUtils for getClassInfo(), findMethods(), findConstructors(), findFields() - Prevent ConcurrentHashMap.putVal() failures when className is null or empty - Add logging for unavailable classes during pre-warming Fixes test failure: FrameworkIntegrationTest.testEventHealthCheckIntegration
1 parent 8cad966 commit 4a307a2

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

warmup-core/src/main/java/io/warmup/framework/asm/AsmCoreUtils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,23 @@ public AsmFieldInfo(String name, String descriptor, String type,
209209
* ✅ OBTIENE INFORMACIÓN COMPLETA DE UNA CLASE USANDO ASM
210210
*/
211211
public static AsmClassInfo getClassInfo(String className) {
212+
// ✅ FIX: Verificar que className no sea null o vacío antes de procesar
213+
if (className == null || className.isEmpty()) {
214+
log.log(Level.WARNING, "Attempted to get class info for null or empty class name");
215+
return null;
216+
}
212217
return asmClassInfoCache.computeIfAbsent(className, AsmCoreUtils::analyzeClassWithASM);
213218
}
214219

215220
/**
216221
* ✅ ENCUENTRA MÉTODOS ESPECÍFICOS EN UNA CLASE
217222
*/
218223
public static List<AsmMethodInfo> findMethods(String className, String methodName) {
224+
// ✅ FIX: Verificar que className no sea null o vacío
225+
if (className == null || className.isEmpty()) {
226+
log.log(Level.WARNING, "Attempted to find methods in null or empty class name");
227+
return new ArrayList<>();
228+
}
219229
String cacheKey = className + "." + methodName;
220230
return asmMethodCache.computeIfAbsent(cacheKey, k -> {
221231
AsmClassInfo classInfo = getClassInfo(className);
@@ -250,6 +260,11 @@ public static AsmMethodInfo findMethodExact(String className, String methodName,
250260
* ✅ ENCUENTRA CONSTRUCTORES ESPECÍFICOS
251261
*/
252262
public static List<AsmConstructorInfo> findConstructors(String className) {
263+
// ✅ FIX: Verificar que className no sea null o vacío
264+
if (className == null || className.isEmpty()) {
265+
log.log(Level.WARNING, "Attempted to find constructors in null or empty class name");
266+
return new ArrayList<>();
267+
}
253268
String cacheKey = className + ".<init>";
254269
return asmConstructorCache.computeIfAbsent(cacheKey, k -> {
255270
AsmClassInfo classInfo = getClassInfo(className);
@@ -277,6 +292,11 @@ public static AsmConstructorInfo findConstructorExact(String className, String..
277292
* ✅ ENCUENTRA CAMPOS ESPECÍFICOS
278293
*/
279294
public static List<AsmFieldInfo> findFields(String className) {
295+
// ✅ FIX: Verificar que className no sea null o vacío
296+
if (className == null || className.isEmpty()) {
297+
log.log(Level.WARNING, "Attempted to find fields in null or empty class name");
298+
return new ArrayList<>();
299+
}
280300
String cacheKey = className + ".<field>";
281301
return asmFieldCache.computeIfAbsent(cacheKey, k -> {
282302
AsmClassInfo classInfo = getClassInfo(className);

warmup-core/src/main/java/io/warmup/framework/core/optimized/ContainerCoordinator.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,28 @@ private void preWarmCriticalCaches(ASMCacheManager cacheManager) {
221221

222222
for (String className : criticalClasses) {
223223
try {
224+
// ✅ FIX: Verificar que className no sea null antes de procesar
225+
if (className == null || className.isEmpty()) {
226+
log.log(Level.FINE, "Skipping null or empty class name in pre-warm");
227+
continue;
228+
}
229+
224230
// Pre-cargar información de clase en cache
225231
// Solo registrar información básica de clase, no bytecode directamente
226232
io.warmup.framework.asm.AsmCoreUtils.AsmClassInfo classInfo =
227233
io.warmup.framework.asm.AsmCoreUtils.getClassInfo(className);
228234
if (classInfo != null) {
229235
// Marcar la clase como pre-cargada para futura optimización
230236
log.log(Level.FINE, "Pre-warmed class info: " + className);
237+
} else {
238+
log.log(Level.FINE, "Class not available for pre-warming: " + className);
231239
}
232240
} catch (Exception e) {
233241
log.log(Level.FINE, "Could not pre-warm class: " + className, e);
234242
}
235243
}
236244

237-
log.log(Level.INFO, "Pre-warmed {0} critical classes in ASM cache", criticalClasses.length);
245+
log.log(Level.INFO, "Pre-warm cache operation completed for critical classes");
238246

239247
} catch (Exception e) {
240248
log.log(Level.WARNING, "Error during cache pre-warming", e);

0 commit comments

Comments
 (0)