From d603e57f72900e74d1d167fd8f34a141f650d8e9 Mon Sep 17 00:00:00 2001 From: Nathan Piper Date: Sat, 21 Nov 2015 13:37:31 +1100 Subject: [PATCH] TypeDescriptor.equals tests equality of annotations (and therefore annotation properties) Issue: SPR-13714 --- .../core/convert/TypeDescriptor.java | 2 +- .../core/convert/TypeDescriptorTests.java | 16 ++++++++++++++++ 2 files changed, 17 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 586cb8390248..31162bc0c4ed 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 @@ -471,7 +471,7 @@ public boolean equals(Object obj) { return false; } for (Annotation ann : getAnnotations()) { - if (other.getAnnotation(ann.annotationType()) == null) { + if (!ObjectUtils.nullSafeEquals(ann, other.getAnnotation(ann.annotationType()))) { return false; } } diff --git a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java index 61f30c314309..629358b218d9 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/TypeDescriptorTests.java @@ -218,6 +218,10 @@ public void testAnnotatedMethod(@ParameterAnnotation(123) String parameter) { } + public void testAnnotatedMethodDifferentAnnotationValue(@ParameterAnnotation(567) String parameter) { + + } + @Test public void propertyComplex() throws Exception { Property property = new Property(getClass(), getClass().getMethod("getComplexProperty"), getClass().getMethod("setComplexProperty", Map.class)); @@ -826,6 +830,18 @@ public void equals() throws Exception { TypeDescriptor t11 = new TypeDescriptor(getClass().getField("mapField")); TypeDescriptor t12 = new TypeDescriptor(getClass().getField("mapField")); assertEquals(t11, t12); + + TypeDescriptor t13 = new TypeDescriptor(new MethodParameter(getClass().getMethod("testAnnotatedMethod", String.class), 0)); + TypeDescriptor t14 = new TypeDescriptor(new MethodParameter(getClass().getMethod("testAnnotatedMethod", String.class), 0)); + assertEquals(t13, t14); + + TypeDescriptor t15 = new TypeDescriptor(new MethodParameter(getClass().getMethod("testAnnotatedMethod", String.class), 0)); + TypeDescriptor t16 = new TypeDescriptor(new MethodParameter(getClass().getMethod("testAnnotatedMethodDifferentAnnotationValue", String.class), 0)); + assertNotEquals(t15, t16); + + TypeDescriptor t17 = new TypeDescriptor(new MethodParameter(getClass().getMethod("testAnnotatedMethod", String.class), 0)); + TypeDescriptor t18 = new TypeDescriptor(new MethodParameter(getClass().getMethod("test5", String.class), 0)); + assertNotEquals(t17, t18); } @Test