Skip to content

Commit e21db26

Browse files
committed
AspectJExpressionPointcut leniently ignores non-composable interfaces
Issue: SPR-17003 (cherry picked from commit bccff73)
1 parent f5dd4d2 commit e21db26

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,15 @@ private ShadowMatch getTargetShadowMatch(Method method, @Nullable Class<?> targe
434434
// Note: AspectJ is only going to take Method.getDeclaringClass() into account.
435435
Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass);
436436
if (ifcs.size() > 1) {
437-
Class<?> compositeInterface = ClassUtils.createCompositeInterface(
438-
ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
439-
targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
437+
try {
438+
Class<?> compositeInterface = ClassUtils.createCompositeInterface(
439+
ClassUtils.toClassArray(ifcs), targetClass.getClassLoader());
440+
targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface);
441+
}
442+
catch (IllegalArgumentException ex) {
443+
// Implemented interfaces probably expose conflicting method signatures...
444+
// Proceed with original target method.
445+
}
440446
}
441447
}
442448
return getShadowMatch(targetMethod, method);
@@ -561,6 +567,19 @@ public String toString() {
561567
return sb.toString();
562568
}
563569

570+
//---------------------------------------------------------------------
571+
// Serialization support
572+
//---------------------------------------------------------------------
573+
574+
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
575+
// Rely on default serialization, just initialize state after deserialization.
576+
ois.defaultReadObject();
577+
578+
// Initialize transient fields.
579+
// pointcutExpression will be initialized lazily by checkReadyToMatch()
580+
this.shadowMatchCache = new ConcurrentHashMap<>(32);
581+
}
582+
564583

565584
/**
566585
* Handler for the Spring-specific {@code bean()} pointcut designator
@@ -657,20 +676,6 @@ private boolean matchesBean(String advisedBeanName) {
657676
}
658677

659678

660-
//---------------------------------------------------------------------
661-
// Serialization support
662-
//---------------------------------------------------------------------
663-
664-
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
665-
// Rely on default serialization, just initialize state after deserialization.
666-
ois.defaultReadObject();
667-
668-
// Initialize transient fields.
669-
// pointcutExpression will be initialized lazily by checkReadyToMatch()
670-
this.shadowMatchCache = new ConcurrentHashMap<>(32);
671-
}
672-
673-
674679
private static class DefensiveShadowMatch implements ShadowMatch {
675680

676681
private final ShadowMatch primary;

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, @Nulla
754754
* @param interfaces the interfaces to merge
755755
* @param classLoader the ClassLoader to create the composite Class in
756756
* @return the merged interface as Class
757+
* @throws IllegalArgumentException if the specified interfaces expose
758+
* conflicting method signatures (or a similar constraint is violated)
757759
* @see java.lang.reflect.Proxy#getProxyClass
758760
*/
759761
@SuppressWarnings("deprecation")

0 commit comments

Comments
 (0)