Skip to content

Commit 1341fd4

Browse files
committed
Consistent use of LinkedHashSet for interfaces (since interface order may matter in subtle cases)
(cherry picked from commit 6f9d7da)
1 parent 473d973 commit 1341fd4

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

spring-aop/src/main/java/org/springframework/aop/IntroductionInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public interface IntroductionInfo {
3434
* Return the additional interfaces introduced by this Advisor or Advice.
3535
* @return the introduced interfaces
3636
*/
37-
Class[] getInterfaces();
37+
Class<?>[] getInterfaces();
3838

3939
}

spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class DeclareParentsAdvisor implements IntroductionAdvisor {
3636

37-
private final Class introducedInterface;
37+
private final Class<?> introducedInterface;
3838

3939
private final ClassFilter typePatternClassFilter;
4040

@@ -47,7 +47,7 @@ public class DeclareParentsAdvisor implements IntroductionAdvisor {
4747
* @param typePattern type pattern the introduction is restricted to
4848
* @param defaultImpl the default implementation class
4949
*/
50-
public DeclareParentsAdvisor(Class interfaceType, String typePattern, Class defaultImpl) {
50+
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> defaultImpl) {
5151
this(interfaceType, typePattern, defaultImpl,
5252
new DelegatePerTargetObjectIntroductionInterceptor(defaultImpl, interfaceType));
5353
}
@@ -58,7 +58,7 @@ public DeclareParentsAdvisor(Class interfaceType, String typePattern, Class defa
5858
* @param typePattern type pattern the introduction is restricted to
5959
* @param delegateRef the delegate implementation object
6060
*/
61-
public DeclareParentsAdvisor(Class interfaceType, String typePattern, Object delegateRef) {
61+
public DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Object delegateRef) {
6262
this(interfaceType, typePattern, delegateRef.getClass(),
6363
new DelegatingIntroductionInterceptor(delegateRef));
6464
}
@@ -71,13 +71,13 @@ public DeclareParentsAdvisor(Class interfaceType, String typePattern, Object del
7171
* @param implementationClass implementation class
7272
* @param advice delegation advice
7373
*/
74-
private DeclareParentsAdvisor(Class interfaceType, String typePattern, Class implementationClass, Advice advice) {
74+
private DeclareParentsAdvisor(Class<?> interfaceType, String typePattern, Class<?> implementationClass, Advice advice) {
7575
this.introducedInterface = interfaceType;
7676
ClassFilter typePatternFilter = new TypePatternClassFilter(typePattern);
7777

7878
// Excludes methods implemented.
7979
ClassFilter exclusion = new ClassFilter() {
80-
public boolean matches(Class clazz) {
80+
public boolean matches(Class<?> clazz) {
8181
return !(introducedInterface.isAssignableFrom(clazz));
8282
}
8383
};
@@ -103,8 +103,8 @@ public Advice getAdvice() {
103103
return this.advice;
104104
}
105105

106-
public Class[] getInterfaces() {
107-
return new Class[] {this.introducedInterface};
106+
public Class<?>[] getInterfaces() {
107+
return new Class<?>[] {this.introducedInterface};
108108
}
109109

110110
}

spring-aop/src/main/java/org/springframework/aop/support/AopUtils.java

Lines changed: 3 additions & 3 deletions
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-2014 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.
@@ -19,7 +19,7 @@
1919
import java.lang.reflect.InvocationTargetException;
2020
import java.lang.reflect.Method;
2121
import java.lang.reflect.Proxy;
22-
import java.util.HashSet;
22+
import java.util.LinkedHashSet;
2323
import java.util.LinkedList;
2424
import java.util.List;
2525
import java.util.Set;
@@ -215,7 +215,7 @@ public static boolean canApply(Pointcut pc, Class<?> targetClass, boolean hasInt
215215
introductionAwareMethodMatcher = (IntroductionAwareMethodMatcher) methodMatcher;
216216
}
217217

218-
Set<Class> classes = new HashSet<Class>(ClassUtils.getAllInterfacesForClassAsSet(targetClass));
218+
Set<Class> classes = new LinkedHashSet<Class>(ClassUtils.getAllInterfacesForClassAsSet(targetClass));
219219
classes.add(targetClass);
220220
for (Class<?> clazz : classes) {
221221
Method[] methods = clazz.getMethods();

spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java

Lines changed: 12 additions & 11 deletions
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-2014 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.
@@ -17,7 +17,7 @@
1717
package org.springframework.aop.support;
1818

1919
import java.io.Serializable;
20-
import java.util.HashSet;
20+
import java.util.LinkedHashSet;
2121
import java.util.Set;
2222

2323
import org.aopalliance.aop.Advice;
@@ -43,7 +43,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
4343

4444
private final Advice advice;
4545

46-
private final Set<Class> interfaces = new HashSet<Class>();
46+
private final Set<Class> interfaces = new LinkedHashSet<Class>();
4747

4848
private int order = Integer.MAX_VALUE;
4949

@@ -68,11 +68,11 @@ public DefaultIntroductionAdvisor(Advice advice, IntroductionInfo introductionIn
6868
Assert.notNull(advice, "Advice must not be null");
6969
this.advice = advice;
7070
if (introductionInfo != null) {
71-
Class[] introducedInterfaces = introductionInfo.getInterfaces();
71+
Class<?>[] introducedInterfaces = introductionInfo.getInterfaces();
7272
if (introducedInterfaces.length == 0) {
7373
throw new IllegalArgumentException("IntroductionAdviceSupport implements no interfaces");
7474
}
75-
for (Class ifc : introducedInterfaces) {
75+
for (Class<?> ifc : introducedInterfaces) {
7676
addInterface(ifc);
7777
}
7878
}
@@ -83,7 +83,7 @@ public DefaultIntroductionAdvisor(Advice advice, IntroductionInfo introductionIn
8383
* @param advice the Advice to apply
8484
* @param intf the interface to introduce
8585
*/
86-
public DefaultIntroductionAdvisor(DynamicIntroductionAdvice advice, Class intf) {
86+
public DefaultIntroductionAdvisor(DynamicIntroductionAdvice advice, Class<?> intf) {
8787
Assert.notNull(advice, "Advice must not be null");
8888
this.advice = advice;
8989
addInterface(intf);
@@ -94,20 +94,21 @@ public DefaultIntroductionAdvisor(DynamicIntroductionAdvice advice, Class intf)
9494
* Add the specified interface to the list of interfaces to introduce.
9595
* @param intf the interface to introduce
9696
*/
97-
public void addInterface(Class intf) {
97+
public void addInterface(Class<?> intf) {
9898
Assert.notNull(intf, "Interface must not be null");
9999
if (!intf.isInterface()) {
100100
throw new IllegalArgumentException("Specified class [" + intf.getName() + "] must be an interface");
101101
}
102102
this.interfaces.add(intf);
103103
}
104104

105-
public Class[] getInterfaces() {
106-
return this.interfaces.toArray(new Class[this.interfaces.size()]);
105+
public Class<?>[] getInterfaces() {
106+
return this.interfaces.toArray(new Class<?>[this.interfaces.size()]);
107107
}
108108

109+
@Override
109110
public void validateInterfaces() throws IllegalArgumentException {
110-
for (Class ifc : this.interfaces) {
111+
for (Class<?> ifc : this.interfaces) {
111112
if (this.advice instanceof DynamicIntroductionAdvice &&
112113
!((DynamicIntroductionAdvice) this.advice).implementsInterface(ifc)) {
113114
throw new IllegalArgumentException("DynamicIntroductionAdvice [" + this.advice + "] " +
@@ -138,7 +139,7 @@ public ClassFilter getClassFilter() {
138139
return this;
139140
}
140141

141-
public boolean matches(Class clazz) {
142+
public boolean matches(Class<?> clazz) {
142143
return true;
143144
}
144145

spring-aop/src/main/java/org/springframework/aop/support/IntroductionInfoSupport.java

Lines changed: 8 additions & 8 deletions
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-2014 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.
@@ -20,7 +20,7 @@
2020
import java.io.ObjectInputStream;
2121
import java.io.Serializable;
2222
import java.lang.reflect.Method;
23-
import java.util.HashSet;
23+
import java.util.LinkedHashSet;
2424
import java.util.Map;
2525
import java.util.Set;
2626
import java.util.concurrent.ConcurrentHashMap;
@@ -43,7 +43,7 @@
4343
@SuppressWarnings("serial")
4444
public class IntroductionInfoSupport implements IntroductionInfo, Serializable {
4545

46-
protected final Set<Class> publishedInterfaces = new HashSet<Class>();
46+
protected final Set<Class> publishedInterfaces = new LinkedHashSet<Class>();
4747

4848
private transient Map<Method, Boolean> rememberedMethods = new ConcurrentHashMap<Method, Boolean>(32);
4949

@@ -55,21 +55,21 @@ public class IntroductionInfoSupport implements IntroductionInfo, Serializable {
5555
* <p>Does nothing if the interface is not implemented by the delegate.
5656
* @param intf the interface to suppress
5757
*/
58-
public void suppressInterface(Class intf) {
58+
public void suppressInterface(Class<?> intf) {
5959
this.publishedInterfaces.remove(intf);
6060
}
6161

62-
public Class[] getInterfaces() {
63-
return this.publishedInterfaces.toArray(new Class[this.publishedInterfaces.size()]);
62+
public Class<?>[] getInterfaces() {
63+
return this.publishedInterfaces.toArray(new Class<?>[this.publishedInterfaces.size()]);
6464
}
6565

6666
/**
6767
* Check whether the specified interfaces is a published introduction interface.
6868
* @param ifc the interface to check
6969
* @return whether the interface is part of this introduction
7070
*/
71-
public boolean implementsInterface(Class ifc) {
72-
for (Class pubIfc : this.publishedInterfaces) {
71+
public boolean implementsInterface(Class<?> ifc) {
72+
for (Class<?> pubIfc : this.publishedInterfaces) {
7373
if (ifc.isInterface() && ifc.isAssignableFrom(pubIfc)) {
7474
return true;
7575
}

0 commit comments

Comments
 (0)