Skip to content

Commit 1b9b513

Browse files
committed
AspectJ matchesMethodExecution call needs to be synchronized (SPR-5687)
1 parent 6495bdd commit 1b9b513

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

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

+23-16
Original file line numberDiff line numberDiff line change
@@ -348,29 +348,36 @@ private void bindParameters(ProxyMethodInvocation invocation, JoinPointMatch jpm
348348
}
349349

350350
private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
351+
// Avoid lock contention for known Methods through concurrent access...
351352
ShadowMatch shadowMatch = this.shadowMatchCache.get(targetMethod);
352353
if (shadowMatch == null) {
353-
try {
354-
shadowMatch = this.pointcutExpression.matchesMethodExecution(targetMethod);
355-
}
356-
catch (ReflectionWorld.ReflectionWorldException ex) {
357-
// Failed to introspect target method, probably because it has been loaded
358-
// in a special ClassLoader. Let's try the original method instead...
359-
if (targetMethod == originalMethod) {
360-
shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null);
361-
}
362-
else {
354+
synchronized (this.shadowMatchCache) {
355+
// Not found - now check again with full lock...
356+
shadowMatch = this.shadowMatchCache.get(targetMethod);
357+
if (shadowMatch == null) {
363358
try {
364-
shadowMatch = this.pointcutExpression.matchesMethodExecution(originalMethod);
359+
shadowMatch = this.pointcutExpression.matchesMethodExecution(targetMethod);
365360
}
366-
catch (ReflectionWorld.ReflectionWorldException ex2) {
367-
// Could neither introspect the target class nor the proxy class ->
368-
// let's simply consider this method as non-matching.
369-
shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null);
361+
catch (ReflectionWorld.ReflectionWorldException ex) {
362+
// Failed to introspect target method, probably because it has been loaded
363+
// in a special ClassLoader. Let's try the original method instead...
364+
if (targetMethod == originalMethod) {
365+
shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null);
366+
}
367+
else {
368+
try {
369+
shadowMatch = this.pointcutExpression.matchesMethodExecution(originalMethod);
370+
}
371+
catch (ReflectionWorld.ReflectionWorldException ex2) {
372+
// Could neither introspect the target class nor the proxy class ->
373+
// let's simply consider this method as non-matching.
374+
shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null);
375+
}
376+
}
370377
}
378+
this.shadowMatchCache.put(targetMethod, shadowMatch);
371379
}
372380
}
373-
this.shadowMatchCache.put(targetMethod, shadowMatch);
374381
}
375382
return shadowMatch;
376383
}

0 commit comments

Comments
 (0)