From 4f6f2c0d41d036c4473e63d34f6d6979c6113bb6 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 5 Jun 2024 16:32:27 +0200 Subject: [PATCH] Revert to separate get/put steps against method cache for concurrency Closes gh-32958 --- .../aop/framework/AdvisedSupport.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index 2aebe1688d7..282d0584be3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -488,20 +488,27 @@ public class AdvisedSupport extends ProxyConfig implements Advised { * @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers) */ public List getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class targetClass) { - if (this.methodCache == null) { + List cachedInterceptors; + if (this.methodCache != null) { + // Method-specific cache for method-specific pointcuts + MethodCacheKey cacheKey = new MethodCacheKey(method); + cachedInterceptors = this.methodCache.get(cacheKey); + if (cachedInterceptors == null) { + cachedInterceptors = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice( + this, method, targetClass); + this.methodCache.put(cacheKey, cachedInterceptors); + } + } + else { // Shared cache since there are no method-specific advisors (see below). - List cachedInterceptors = this.cachedInterceptors; + cachedInterceptors = this.cachedInterceptors; if (cachedInterceptors == null) { cachedInterceptors = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice( this, method, targetClass); this.cachedInterceptors = cachedInterceptors; } - return cachedInterceptors; } - - // Method-specific cache for method-specific pointcuts - return this.methodCache.computeIfAbsent(new MethodCacheKey(method), k -> - this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(this, method, targetClass)); + return cachedInterceptors; } /**