From e21db2619bd95991548d15147144b94bca7a4cad Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 22 Jul 2018 22:28:48 +0200 Subject: [PATCH] AspectJExpressionPointcut leniently ignores non-composable interfaces Issue: SPR-17003 (cherry picked from commit bccff73) --- .../aspectj/AspectJExpressionPointcut.java | 39 +++++++++++-------- .../org/springframework/util/ClassUtils.java | 2 + 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java index 5f3a68e4ca..8a2b25d539 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcut.java @@ -434,9 +434,15 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut // Note: AspectJ is only going to take Method.getDeclaringClass() into account. Set> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass); if (ifcs.size() > 1) { - Class compositeInterface = ClassUtils.createCompositeInterface( - ClassUtils.toClassArray(ifcs), targetClass.getClassLoader()); - targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface); + try { + Class compositeInterface = ClassUtils.createCompositeInterface( + ClassUtils.toClassArray(ifcs), targetClass.getClassLoader()); + targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface); + } + catch (IllegalArgumentException ex) { + // Implemented interfaces probably expose conflicting method signatures... + // Proceed with original target method. + } } } return getShadowMatch(targetMethod, method); @@ -561,6 +567,19 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut return sb.toString(); } + //--------------------------------------------------------------------- + // Serialization support + //--------------------------------------------------------------------- + + private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { + // Rely on default serialization, just initialize state after deserialization. + ois.defaultReadObject(); + + // Initialize transient fields. + // pointcutExpression will be initialized lazily by checkReadyToMatch() + this.shadowMatchCache = new ConcurrentHashMap<>(32); + } + /** * Handler for the Spring-specific {@code bean()} pointcut designator @@ -657,20 +676,6 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut } - //--------------------------------------------------------------------- - // Serialization support - //--------------------------------------------------------------------- - - private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { - // Rely on default serialization, just initialize state after deserialization. - ois.defaultReadObject(); - - // Initialize transient fields. - // pointcutExpression will be initialized lazily by checkReadyToMatch() - this.shadowMatchCache = new ConcurrentHashMap<>(32); - } - - private static class DefensiveShadowMatch implements ShadowMatch { private final ShadowMatch primary; diff --git a/spring-core/src/main/java/org/springframework/util/ClassUtils.java b/spring-core/src/main/java/org/springframework/util/ClassUtils.java index f274ef24fb..59663421bc 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -754,6 +754,8 @@ public abstract class ClassUtils { * @param interfaces the interfaces to merge * @param classLoader the ClassLoader to create the composite Class in * @return the merged interface as Class + * @throws IllegalArgumentException if the specified interfaces expose + * conflicting method signatures (or a similar constraint is violated) * @see java.lang.reflect.Proxy#getProxyClass */ @SuppressWarnings("deprecation")