Skip to content

Commit be2d915

Browse files
committed
Consistent equals/hashCode/toString implementations in AnnotationMatchingPointcut/ClassFilter/MethodMatcher
Issue: SPR-11275 Issue: SPR-11276 (cherry picked from commit 0de307b)
1 parent 6045914 commit be2d915

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,10 +59,32 @@ public AnnotationClassFilter(Class<? extends Annotation> annotationType, boolean
5959
}
6060

6161

62-
public boolean matches(Class clazz) {
62+
public boolean matches(Class<?> clazz) {
6363
return (this.checkInherited ?
6464
(AnnotationUtils.findAnnotation(clazz, this.annotationType) != null) :
6565
clazz.isAnnotationPresent(this.annotationType));
6666
}
6767

68+
@Override
69+
public boolean equals(Object other) {
70+
if (this == other) {
71+
return true;
72+
}
73+
if (!(other instanceof AnnotationClassFilter)) {
74+
return false;
75+
}
76+
AnnotationClassFilter otherCf = (AnnotationClassFilter) other;
77+
return (this.annotationType.equals(otherCf.annotationType) && this.checkInherited == otherCf.checkInherited);
78+
}
79+
80+
@Override
81+
public int hashCode() {
82+
return this.annotationType.hashCode();
83+
}
84+
85+
@Override
86+
public String toString() {
87+
return getClass().getName() + ": " + this.annotationType;
88+
}
89+
6890
}

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import org.springframework.aop.MethodMatcher;
2323
import org.springframework.aop.Pointcut;
2424
import org.springframework.util.Assert;
25+
import org.springframework.util.ObjectUtils;
2526

2627
/**
2728
* Simple Pointcut that looks for a specific Java 5 annotation
@@ -98,6 +99,36 @@ public MethodMatcher getMethodMatcher() {
9899
return this.methodMatcher;
99100
}
100101

102+
@Override
103+
public boolean equals(Object other) {
104+
if (this == other) {
105+
return true;
106+
}
107+
if (!(other instanceof AnnotationMatchingPointcut)) {
108+
return false;
109+
}
110+
AnnotationMatchingPointcut that = (AnnotationMatchingPointcut) other;
111+
return ObjectUtils.nullSafeEquals(that.classFilter, this.classFilter) &&
112+
ObjectUtils.nullSafeEquals(that.methodMatcher, this.methodMatcher);
113+
}
114+
115+
@Override
116+
public int hashCode() {
117+
int code = 17;
118+
if (this.classFilter != null) {
119+
code = 37 * code + this.classFilter.hashCode();
120+
}
121+
if (this.methodMatcher != null) {
122+
code = 37 * code + this.methodMatcher.hashCode();
123+
}
124+
return code;
125+
}
126+
127+
@Override
128+
public String toString() {
129+
return "AnnotationMatchingPointcut: " + this.classFilter + ", " +this.methodMatcher;
130+
}
131+
101132

102133
/**
103134
* Factory method for an AnnotationMatchingPointcut that matches

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -73,4 +73,9 @@ public int hashCode() {
7373
return this.annotationType.hashCode();
7474
}
7575

76+
@Override
77+
public String toString() {
78+
return getClass().getName() + ": " + this.annotationType;
79+
}
80+
7681
}

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationAdvisor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected Pointcut buildPointcut(Set<Class<? extends Annotation>> asyncAnnotatio
140140
ComposablePointcut result = null;
141141
for (Class<? extends Annotation> asyncAnnotationType : asyncAnnotationTypes) {
142142
Pointcut cpc = new AnnotationMatchingPointcut(asyncAnnotationType, true);
143-
Pointcut mpc = new AnnotationMatchingPointcut(null, asyncAnnotationType);
143+
Pointcut mpc = AnnotationMatchingPointcut.forMethodAnnotation(asyncAnnotationType);
144144
if (result == null) {
145145
result = new ComposablePointcut(cpc).union(mpc);
146146
}

0 commit comments

Comments
 (0)