Skip to content

Commit b3005fc

Browse files
committed
Merge branch '6.1.x'
2 parents b2d43f5 + a4135ba commit b3005fc

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

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

+14-9
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,30 @@ public void setBeanFactory(BeanFactory beanFactory) {
164164

165165
@Override
166166
public ClassFilter getClassFilter() {
167-
obtainPointcutExpression();
167+
checkExpression();
168168
return this;
169169
}
170170

171171
@Override
172172
public MethodMatcher getMethodMatcher() {
173-
obtainPointcutExpression();
173+
checkExpression();
174174
return this;
175175
}
176176

177177

178178
/**
179-
* Check whether this pointcut is ready to match,
180-
* lazily building the underlying AspectJ pointcut expression.
179+
* Check whether this pointcut is ready to match.
181180
*/
182-
private PointcutExpression obtainPointcutExpression() {
181+
private void checkExpression() {
183182
if (getExpression() == null) {
184183
throw new IllegalStateException("Must set property 'expression' before attempting to match");
185184
}
185+
}
186+
187+
/**
188+
* Lazily build the underlying AspectJ pointcut expression.
189+
*/
190+
private PointcutExpression obtainPointcutExpression() {
186191
if (this.pointcutExpression == null) {
187192
this.pointcutClassLoader = determinePointcutClassLoader();
188193
this.pointcutExpression = buildPointcutExpression(this.pointcutClassLoader);
@@ -259,10 +264,9 @@ public PointcutExpression getPointcutExpression() {
259264

260265
@Override
261266
public boolean matches(Class<?> targetClass) {
262-
PointcutExpression pointcutExpression = obtainPointcutExpression();
263267
try {
264268
try {
265-
return pointcutExpression.couldMatchJoinPointsInType(targetClass);
269+
return obtainPointcutExpression().couldMatchJoinPointsInType(targetClass);
266270
}
267271
catch (ReflectionWorldException ex) {
268272
logger.debug("PointcutExpression matching rejected target class - trying fallback expression", ex);
@@ -273,6 +277,9 @@ public boolean matches(Class<?> targetClass) {
273277
}
274278
}
275279
}
280+
catch (IllegalArgumentException | IllegalStateException ex) {
281+
throw ex;
282+
}
276283
catch (Throwable ex) {
277284
logger.debug("PointcutExpression matching rejected target class", ex);
278285
}
@@ -281,7 +288,6 @@ public boolean matches(Class<?> targetClass) {
281288

282289
@Override
283290
public boolean matches(Method method, Class<?> targetClass, boolean hasIntroductions) {
284-
obtainPointcutExpression();
285291
ShadowMatch shadowMatch = getTargetShadowMatch(method, targetClass);
286292

287293
// Special handling for this, target, @this, @target, @annotation
@@ -319,7 +325,6 @@ public boolean isRuntime() {
319325

320326
@Override
321327
public boolean matches(Method method, Class<?> targetClass, Object... args) {
322-
obtainPointcutExpression();
323328
ShadowMatch shadowMatch = getTargetShadowMatch(method, targetClass);
324329

325330
// Bind Spring AOP proxy to AspectJ "this" and Spring AOP target to AspectJ target,

spring-aop/src/test/java/org/springframework/aop/aspectj/AspectJExpressionPointcutTests.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
import org.aopalliance.intercept.MethodInterceptor;
2525
import org.aopalliance.intercept.MethodInvocation;
26-
import org.aspectj.weaver.tools.PointcutPrimitive;
27-
import org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException;
2826
import org.junit.jupiter.api.BeforeEach;
2927
import org.junit.jupiter.api.Test;
3028
import test.annotation.EmptySpringAnnotation;
@@ -41,7 +39,6 @@
4139
import org.springframework.beans.testfixture.beans.subpkg.DeepBean;
4240

4341
import static org.assertj.core.api.Assertions.assertThat;
44-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4542
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
4643
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
4744

@@ -174,23 +171,23 @@ private void testWithinPackage(boolean matchSubpackages) throws SecurityExceptio
174171
void testFriendlyErrorOnNoLocationClassMatching() {
175172
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
176173
assertThatIllegalStateException()
177-
.isThrownBy(() -> pc.matches(ITestBean.class))
174+
.isThrownBy(() -> pc.getClassFilter().matches(ITestBean.class))
178175
.withMessageContaining("expression");
179176
}
180177

181178
@Test
182179
void testFriendlyErrorOnNoLocation2ArgMatching() {
183180
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
184181
assertThatIllegalStateException()
185-
.isThrownBy(() -> pc.matches(getAge, ITestBean.class))
182+
.isThrownBy(() -> pc.getMethodMatcher().matches(getAge, ITestBean.class))
186183
.withMessageContaining("expression");
187184
}
188185

189186
@Test
190187
void testFriendlyErrorOnNoLocation3ArgMatching() {
191188
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
192189
assertThatIllegalStateException()
193-
.isThrownBy(() -> pc.matches(getAge, ITestBean.class, (Object[]) null))
190+
.isThrownBy(() -> pc.getMethodMatcher().matches(getAge, ITestBean.class, (Object[]) null))
194191
.withMessageContaining("expression");
195192
}
196193

@@ -246,7 +243,7 @@ void testDynamicMatchingProxy() {
246243
@Test
247244
void testInvalidExpression() {
248245
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)";
249-
assertThatIllegalArgumentException().isThrownBy(getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
246+
assertThatIllegalArgumentException().isThrownBy(() -> getPointcut(expression).getClassFilter().matches(Object.class));
250247
}
251248

252249
private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
@@ -276,9 +273,7 @@ private void assertMatchesTestBeanClass(ClassFilter classFilter) {
276273
@Test
277274
void testWithUnsupportedPointcutPrimitive() {
278275
String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())";
279-
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class)
280-
.isThrownBy(() -> getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
281-
.satisfies(ex -> assertThat(ex.getUnsupportedPrimitive()).isEqualTo(PointcutPrimitive.CALL));
276+
assertThat(getPointcut(expression).getClassFilter().matches(Object.class)).isFalse();
282277
}
283278

284279
@Test

0 commit comments

Comments
 (0)