Skip to content

Commit

Permalink
Avoid potential leak in PropertyUtils cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne committed May 15, 2024
1 parent a37c050 commit e14c1e4
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package io.quarkus.deployment.recording;

import java.lang.reflect.Method;
Expand All @@ -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<Class<?>, Property[]> CACHE = new ConcurrentHashMap<>();

private static final Function<Class<?>, Property[]> FUNCTION = new Function<Class<?>, Property[]>() {
private static final ClassValue<Property[]> CACHE = new ClassValue<Property[]>() {
@Override
public Property[] apply(Class<?> type) {
protected Property[] computeValue(Class<?> type) {
if (type.isRecord()) {
RecordComponent[] recordComponents = type.getRecordComponents();
return Arrays.stream(recordComponents)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e14c1e4

Please sign in to comment.