From a159dd599321a43a3c0ac6365985828c069ff0c5 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 9 Aug 2018 01:52:16 +0200 Subject: [PATCH] AbstractAspectJAdvisorFactory uses AnnotationUtils.getValue --- .../annotation/AbstractAspectJAdvisorFactory.java | 13 ++++++++----- .../core/annotation/AnnotationUtils.java | 3 +++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java index a091f4d1f0..6f80b15a08 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java @@ -42,7 +42,6 @@ import org.springframework.aop.framework.AopConfigException; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.lang.Nullable; -import org.springframework.util.StringUtils; /** * Abstract base class for factories that can create Spring AOP Advisors @@ -200,7 +199,8 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac // but need to invoke them reflectively as there isn't a common interface. try { this.pointcutExpression = resolveExpression(annotation); - this.argumentNames = (String) annotation.getClass().getMethod("argNames").invoke(annotation); + Object argNames = AnnotationUtils.getValue(annotation, "argNames"); + this.argumentNames = (argNames instanceof String ? (String) argNames : ""); } catch (Exception ex) { throw new IllegalArgumentException(annotation + " is not a valid AspectJ annotation", ex); @@ -217,9 +217,12 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac private String resolveExpression(A annotation) { for (String attributeName : EXPRESSION_ATTRIBUTES) { - String candidate = (String) AnnotationUtils.getValue(annotation, attributeName); - if (StringUtils.hasText(candidate)) { - return candidate; + Object val = AnnotationUtils.getValue(annotation, attributeName); + if (val instanceof String) { + String str = (String) val; + if (!str.isEmpty()) { + return str; + } } } throw new IllegalStateException("Failed to resolve expression: " + annotation); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 51c417cd77..4698698e53 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -1392,6 +1392,9 @@ public abstract class AnnotationUtils { ReflectionUtils.makeAccessible(method); return method.invoke(annotation); } + catch (NoSuchMethodException ex) { + return null; + } catch (InvocationTargetException ex) { rethrowAnnotationConfigurationException(ex.getTargetException()); throw new IllegalStateException(