|
16 | 16 |
|
17 | 17 | package org.springframework.aop.aspectj;
|
18 | 18 |
|
19 |
| -import java.io.IOException; |
20 |
| -import java.io.ObjectInputStream; |
21 | 19 | import java.lang.reflect.Method;
|
22 | 20 | import java.lang.reflect.Proxy;
|
23 | 21 | import java.util.Arrays;
|
24 |
| -import java.util.Map; |
25 | 22 | import java.util.Set;
|
26 |
| -import java.util.concurrent.ConcurrentHashMap; |
27 | 23 |
|
28 | 24 | import org.aopalliance.intercept.MethodInvocation;
|
29 | 25 | import org.apache.commons.logging.Log;
|
@@ -115,8 +111,6 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
115 | 111 | @Nullable
|
116 | 112 | private transient PointcutExpression pointcutExpression;
|
117 | 113 |
|
118 |
| - private transient Map<Method, ShadowMatch> shadowMatchCache = new ConcurrentHashMap<>(32); |
119 |
| - |
120 | 114 |
|
121 | 115 | /**
|
122 | 116 | * Create a new default AspectJExpressionPointcut.
|
@@ -447,72 +441,66 @@ private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) {
|
447 | 441 | }
|
448 | 442 |
|
449 | 443 | private ShadowMatch getShadowMatch(Method targetMethod, Method originalMethod) {
|
450 |
| - // Avoid lock contention for known Methods through concurrent access... |
451 |
| - ShadowMatch shadowMatch = this.shadowMatchCache.get(targetMethod); |
| 444 | + String expression = resolveExpression(); |
| 445 | + ShadowMatch shadowMatch = ShadowMatchUtils.getShadowMatch(this, targetMethod); |
452 | 446 | if (shadowMatch == null) {
|
453 |
| - synchronized (this.shadowMatchCache) { |
454 |
| - // Not found - now check again with full lock... |
455 |
| - PointcutExpression fallbackExpression = null; |
456 |
| - shadowMatch = this.shadowMatchCache.get(targetMethod); |
457 |
| - if (shadowMatch == null) { |
458 |
| - Method methodToMatch = targetMethod; |
| 447 | + PointcutExpression fallbackExpression = null; |
| 448 | + Method methodToMatch = targetMethod; |
| 449 | + try { |
| 450 | + try { |
| 451 | + shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch); |
| 452 | + } |
| 453 | + catch (ReflectionWorldException ex) { |
| 454 | + // Failed to introspect target method, probably because it has been loaded |
| 455 | + // in a special ClassLoader. Let's try the declaring ClassLoader instead... |
459 | 456 | try {
|
460 |
| - try { |
461 |
| - shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch); |
462 |
| - } |
463 |
| - catch (ReflectionWorldException ex) { |
464 |
| - // Failed to introspect target method, probably because it has been loaded |
465 |
| - // in a special ClassLoader. Let's try the declaring ClassLoader instead... |
466 |
| - try { |
467 |
| - fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass()); |
468 |
| - if (fallbackExpression != null) { |
469 |
| - shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch); |
470 |
| - } |
471 |
| - } |
472 |
| - catch (ReflectionWorldException ex2) { |
473 |
| - fallbackExpression = null; |
474 |
| - } |
475 |
| - } |
476 |
| - if (targetMethod != originalMethod && (shadowMatch == null || |
477 |
| - (Proxy.isProxyClass(targetMethod.getDeclaringClass()) && |
478 |
| - (shadowMatch.neverMatches() || containsAnnotationPointcut())))) { |
479 |
| - // Fall back to the plain original method in case of no resolvable match or a |
480 |
| - // negative match on a proxy class (which doesn't carry any annotations on its |
481 |
| - // redeclared methods), as well as for annotation pointcuts. |
482 |
| - methodToMatch = originalMethod; |
483 |
| - try { |
484 |
| - shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch); |
485 |
| - } |
486 |
| - catch (ReflectionWorldException ex) { |
487 |
| - // Could neither introspect the target class nor the proxy class -> |
488 |
| - // let's try the original method's declaring class before we give up... |
489 |
| - try { |
490 |
| - fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass()); |
491 |
| - if (fallbackExpression != null) { |
492 |
| - shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch); |
493 |
| - } |
494 |
| - } |
495 |
| - catch (ReflectionWorldException ex2) { |
496 |
| - fallbackExpression = null; |
497 |
| - } |
498 |
| - } |
| 457 | + fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass()); |
| 458 | + if (fallbackExpression != null) { |
| 459 | + shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch); |
499 | 460 | }
|
500 | 461 | }
|
501 |
| - catch (Throwable ex) { |
502 |
| - // Possibly AspectJ 1.8.10 encountering an invalid signature |
503 |
| - logger.debug("PointcutExpression matching rejected target method", ex); |
| 462 | + catch (ReflectionWorldException ex2) { |
504 | 463 | fallbackExpression = null;
|
505 | 464 | }
|
506 |
| - if (shadowMatch == null) { |
507 |
| - shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null); |
| 465 | + } |
| 466 | + if (targetMethod != originalMethod && (shadowMatch == null || |
| 467 | + (Proxy.isProxyClass(targetMethod.getDeclaringClass()) && |
| 468 | + (shadowMatch.neverMatches() || containsAnnotationPointcut())))) { |
| 469 | + // Fall back to the plain original method in case of no resolvable match or a |
| 470 | + // negative match on a proxy class (which doesn't carry any annotations on its |
| 471 | + // redeclared methods), as well as for annotation pointcuts. |
| 472 | + methodToMatch = originalMethod; |
| 473 | + try { |
| 474 | + shadowMatch = obtainPointcutExpression().matchesMethodExecution(methodToMatch); |
508 | 475 | }
|
509 |
| - else if (shadowMatch.maybeMatches() && fallbackExpression != null) { |
510 |
| - shadowMatch = new DefensiveShadowMatch(shadowMatch, |
511 |
| - fallbackExpression.matchesMethodExecution(methodToMatch)); |
| 476 | + catch (ReflectionWorldException ex) { |
| 477 | + // Could neither introspect the target class nor the proxy class -> |
| 478 | + // let's try the original method's declaring class before we give up... |
| 479 | + try { |
| 480 | + fallbackExpression = getFallbackPointcutExpression(methodToMatch.getDeclaringClass()); |
| 481 | + if (fallbackExpression != null) { |
| 482 | + shadowMatch = fallbackExpression.matchesMethodExecution(methodToMatch); |
| 483 | + } |
| 484 | + } |
| 485 | + catch (ReflectionWorldException ex2) { |
| 486 | + fallbackExpression = null; |
| 487 | + } |
512 | 488 | }
|
513 |
| - this.shadowMatchCache.put(targetMethod, shadowMatch); |
514 | 489 | }
|
515 | 490 | }
|
| 491 | + catch (Throwable ex) { |
| 492 | + // Possibly AspectJ 1.8.10 encountering an invalid signature |
| 493 | + logger.debug("PointcutExpression matching rejected target method", ex); |
| 494 | + fallbackExpression = null; |
| 495 | + } |
| 496 | + if (shadowMatch == null) { |
| 497 | + shadowMatch = new ShadowMatchImpl(org.aspectj.util.FuzzyBoolean.NO, null, null, null); |
| 498 | + } |
| 499 | + else if (shadowMatch.maybeMatches() && fallbackExpression != null) { |
| 500 | + shadowMatch = new DefensiveShadowMatch(shadowMatch, |
| 501 | + fallbackExpression.matchesMethodExecution(methodToMatch)); |
| 502 | + } |
| 503 | + shadowMatch = ShadowMatchUtils.setShadowMatch(this, targetMethod, shadowMatch); |
516 | 504 | }
|
517 | 505 | return shadowMatch;
|
518 | 506 | }
|
@@ -558,19 +546,6 @@ public String toString() {
|
558 | 546 | return sb.toString();
|
559 | 547 | }
|
560 | 548 |
|
561 |
| - //--------------------------------------------------------------------- |
562 |
| - // Serialization support |
563 |
| - //--------------------------------------------------------------------- |
564 |
| - |
565 |
| - private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { |
566 |
| - // Rely on default serialization, just initialize state after deserialization. |
567 |
| - ois.defaultReadObject(); |
568 |
| - |
569 |
| - // Initialize transient fields. |
570 |
| - // pointcutExpression will be initialized lazily by checkReadyToMatch() |
571 |
| - this.shadowMatchCache = new ConcurrentHashMap<>(32); |
572 |
| - } |
573 |
| - |
574 | 549 |
|
575 | 550 | /**
|
576 | 551 | * Handler for the Spring-specific {@code bean()} pointcut designator
|
|
0 commit comments