From 8ecae8697a2215dee5bfeadbc868da55dfe002e1 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 24 May 2015 15:55:54 +0200 Subject: [PATCH] Cache attribute methods in AnnotationUtils Issue: SPR-11512 --- .../core/annotation/AnnotationUtils.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 419d6ddbe7..ec57c0230a 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -121,6 +121,9 @@ public abstract class AnnotationUtils { private static final Map, Map> attributeAliasesCache = new ConcurrentReferenceHashMap, Map>(256); + private static final Map, List> attributeMethodsCache = + new ConcurrentReferenceHashMap, List>(256); + private static transient Log logger; @@ -1311,13 +1314,22 @@ public abstract class AnnotationUtils { * @since 4.2 */ static List getAttributeMethods(Class annotationType) { - List methods = new ArrayList(); + + List methods = attributeMethodsCache.get(annotationType); + if (methods != null) { + return methods; + } + + methods = new ArrayList(); for (Method method : annotationType.getDeclaredMethods()) { if ((method.getParameterTypes().length == 0) && (method.getReturnType() != void.class)) { ReflectionUtils.makeAccessible(method); methods.add(method); } } + + attributeMethodsCache.put(annotationType, methods); + return methods; }