From e14c1e4689f77e1f9454015f7810dddf0dd4aedb Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Mon, 13 May 2024 20:54:55 +0100 Subject: [PATCH] Avoid potential leak in PropertyUtils cache --- .../quarkus/deployment/recording/PropertyUtils.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkus/deployment/recording/PropertyUtils.java b/core/deployment/src/main/java/io/quarkus/deployment/recording/PropertyUtils.java index da8594e88766aa..8cd2c89ea04f57 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/recording/PropertyUtils.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/recording/PropertyUtils.java @@ -1,4 +1,3 @@ - package io.quarkus.deployment.recording; import java.lang.reflect.Method; @@ -10,17 +9,12 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.function.Function; final class PropertyUtils { - static final ConcurrentMap, Property[]> CACHE = new ConcurrentHashMap<>(); - - private static final Function, Property[]> FUNCTION = new Function, Property[]>() { + private static final ClassValue CACHE = new ClassValue() { @Override - public Property[] apply(Class type) { + protected Property[] computeValue(Class type) { if (type.isRecord()) { RecordComponent[] recordComponents = type.getRecordComponents(); return Arrays.stream(recordComponents) @@ -84,7 +78,7 @@ public Property[] apply(Class type) { }; public static Property[] getPropertyDescriptors(Object param) { - return CACHE.computeIfAbsent(param.getClass(), FUNCTION); + return CACHE.get(param.getClass()); } public static class Property {