From cde476f90eb3970d04b847b7728ef60cfbf1dece Mon Sep 17 00:00:00 2001 From: hzmpay Date: Wed, 4 Nov 2020 15:00:11 +0800 Subject: [PATCH 1/2] Use computeIfAbsent in SpelCompiler and AdvisedSupport See gh-26028 --- .../springframework/aop/framework/AdvisedSupport.java | 10 ++-------- .../expression/spel/standard/SpelCompiler.java | 6 +----- 2 files changed, 3 insertions(+), 13 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 d88c58aa3b..d77e714b67 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 @@ -479,14 +479,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised { * @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers) */ public List getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class targetClass) { - MethodCacheKey cacheKey = new MethodCacheKey(method); - List cached = this.methodCache.get(cacheKey); - if (cached == null) { - cached = this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice( - this, method, targetClass); - this.methodCache.put(cacheKey, cached); - } - return cached; + return this.methodCache.computeIfAbsent(new MethodCacheKey(method), k -> + this.advisorChainFactory.getInterceptorsAndDynamicInterceptionAdvice(this, method, targetClass)); } /** diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java index 695d82c1b3..90a2d4b1cf 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java @@ -233,11 +233,7 @@ public final class SpelCompiler implements Opcodes { if (compiler == null) { // Full lock now since we're creating a child ClassLoader synchronized (compilers) { - compiler = compilers.get(clToUse); - if (compiler == null) { - compiler = new SpelCompiler(clToUse); - compilers.put(clToUse, compiler); - } + return compilers.computeIfAbsent(clToUse, SpelCompiler::new); } } return compiler; From 8432f777aa648a5f83e2f6a40d5901785838dc4c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 25 Aug 2023 16:13:27 +0200 Subject: [PATCH 2/2] Update copyright header of changed file See gh-26028 --- .../springframework/expression/spel/standard/SpelCompiler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java index 90a2d4b1cf..0b30e76eab 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.