From 794580ffcdcce68bba114bd639cba60658a9da63 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 28 Dec 2016 22:51:29 +0100 Subject: [PATCH] TypeDescriptor efficiently matches equal annotations as well Issue: SPR-15060 (cherry picked from commit e38c020) --- .../org/springframework/core/convert/TypeDescriptor.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java index 30763e66ace..593687efa88 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java @@ -483,7 +483,7 @@ public class TypeDescriptor implements Serializable { } if (anns.length > 0) { for (int i = 0; i < anns.length; i++) { - if (anns[i] != otherAnns[i]) { + if (!annotationEquals(anns[i], otherAnns[i])) { return false; } } @@ -491,6 +491,11 @@ public class TypeDescriptor implements Serializable { return true; } + private boolean annotationEquals(Annotation ann, Annotation otherAnn) { + // Annotation.equals is reflective and pretty slow, so let's check identity and proxy type first. + return (ann == otherAnn || (ann.getClass() == otherAnn.getClass() && ann.equals(otherAnn))); + } + @Override public int hashCode() { return getType().hashCode();