Skip to content

Commit 7029042

Browse files
committed
Polishing
(cherry picked from commit e9110c0)
1 parent 1a5661d commit 7029042

File tree

19 files changed

+94
-118
lines changed

19 files changed

+94
-118
lines changed

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,12 +29,10 @@
2929
import org.springframework.lang.Nullable;
3030

3131
/**
32-
* Abstract implementation of {@link JCacheOperationSource} that caches attributes
32+
* Abstract implementation of {@link JCacheOperationSource} that caches operations
3333
* for methods and implements a fallback policy: 1. specific target method;
3434
* 2. declaring method.
3535
*
36-
* <p>This implementation caches attributes by method after they are first used.
37-
*
3836
* @author Stephane Nicoll
3937
* @author Juergen Hoeller
4038
* @since 4.1
@@ -43,35 +41,36 @@
4341
public abstract class AbstractFallbackJCacheOperationSource implements JCacheOperationSource {
4442

4543
/**
46-
* Canonical value held in cache to indicate no caching attribute was
47-
* found for this method and we don't need to look again.
44+
* Canonical value held in cache to indicate no cache operation was
45+
* found for this method, and we don't need to look again.
4846
*/
49-
private static final Object NULL_CACHING_ATTRIBUTE = new Object();
47+
private static final Object NULL_CACHING_MARKER = new Object();
5048

5149

5250
protected final Log logger = LogFactory.getLog(getClass());
5351

54-
private final Map<MethodClassKey, Object> cache = new ConcurrentHashMap<>(1024);
52+
private final Map<MethodClassKey, Object> operationCache = new ConcurrentHashMap<>(1024);
5553

5654

5755
@Override
56+
@Nullable
5857
public JCacheOperation<?> getCacheOperation(Method method, @Nullable Class<?> targetClass) {
5958
MethodClassKey cacheKey = new MethodClassKey(method, targetClass);
60-
Object cached = this.cache.get(cacheKey);
59+
Object cached = this.operationCache.get(cacheKey);
6160

6261
if (cached != null) {
63-
return (cached != NULL_CACHING_ATTRIBUTE ? (JCacheOperation<?>) cached : null);
62+
return (cached != NULL_CACHING_MARKER ? (JCacheOperation<?>) cached : null);
6463
}
6564
else {
6665
JCacheOperation<?> operation = computeCacheOperation(method, targetClass);
6766
if (operation != null) {
6867
if (logger.isDebugEnabled()) {
6968
logger.debug("Adding cacheable method '" + method.getName() + "' with operation: " + operation);
7069
}
71-
this.cache.put(cacheKey, operation);
70+
this.operationCache.put(cacheKey, operation);
7271
}
7372
else {
74-
this.cache.put(cacheKey, NULL_CACHING_ATTRIBUTE);
73+
this.operationCache.put(cacheKey, NULL_CACHING_MARKER);
7574
}
7675
return operation;
7776
}
@@ -84,7 +83,7 @@ private JCacheOperation<?> computeCacheOperation(Method method, @Nullable Class<
8483
return null;
8584
}
8685

87-
// The method may be on an interface, but we need attributes from the target class.
86+
// The method may be on an interface, but we need metadata from the target class.
8887
// If the target class is null, the method will be unchanged.
8988
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
9089

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AnnotationJCacheOperationSource.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -212,10 +212,8 @@ protected String generateDefaultCacheName(Method method) {
212212
for (Class<?> parameterType : parameterTypes) {
213213
parameters.add(parameterType.getName());
214214
}
215-
216-
return method.getDeclaringClass().getName()
217-
+ '.' + method.getName()
218-
+ '(' + StringUtils.collectionToCommaDelimitedString(parameters) + ')';
215+
return method.getDeclaringClass().getName() + '.' + method.getName() +
216+
'(' + StringUtils.collectionToCommaDelimitedString(parameters) + ')';
219217
}
220218

221219
private int countNonNull(Object... instances) {

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/BeanFactoryJCacheOperationSourceAdvisor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,7 @@ public class BeanFactoryJCacheOperationSourceAdvisor extends AbstractBeanFactory
4646
* Set the cache operation attribute source which is used to find cache
4747
* attributes. This should usually be identical to the source reference
4848
* set on the cache interceptor itself.
49+
* @see JCacheInterceptor#setCacheOperationSource
4950
*/
5051
public void setCacheOperationSource(JCacheOperationSource cacheOperationSource) {
5152
this.pointcut.setCacheOperationSource(cacheOperationSource);

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ public interface JCacheOperationSource {
3434
* Return the cache operations for this method, or {@code null}
3535
* if the method contains no <em>JSR-107</em> related metadata.
3636
* @param method the method to introspect
37-
* @param targetClass the target class (may be {@code null}, in which case
37+
* @param targetClass the target class (can be {@code null}, in which case
3838
* the declaring class of the method must be used)
3939
* @return the cache operation for this method, or {@code null} if none found
4040
*/

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424
import org.springframework.util.ObjectUtils;
2525

2626
/**
27-
* A Pointcut that matches if the underlying {@link JCacheOperationSource}
27+
* A {@code Pointcut} that matches if the underlying {@link JCacheOperationSource}
2828
* has an operation for a given method.
2929
*
3030
* @author Stephane Nicoll

spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,31 +32,27 @@
3232
import org.springframework.util.ClassUtils;
3333

3434
/**
35-
* Abstract implementation of {@link CacheOperation} that caches attributes
35+
* Abstract implementation of {@link CacheOperationSource} that caches operations
3636
* for methods and implements a fallback policy: 1. specific target method;
3737
* 2. target class; 3. declaring method; 4. declaring class/interface.
3838
*
39-
* <p>Defaults to using the target class's caching attribute if none is
40-
* associated with the target method. Any caching attribute associated with
41-
* the target method completely overrides a class caching attribute.
39+
* <p>Defaults to using the target class's declared cache operations if none are
40+
* associated with the target method. Any cache operations associated with
41+
* the target method completely override any class-level declarations.
4242
* If none found on the target class, the interface that the invoked method
4343
* has been called through (in case of a JDK proxy) will be checked.
4444
*
45-
* <p>This implementation caches attributes by method after they are first
46-
* used. If it is ever desirable to allow dynamic changing of cacheable
47-
* attributes (which is very unlikely), caching could be made configurable.
48-
*
4945
* @author Costin Leau
5046
* @author Juergen Hoeller
5147
* @since 3.1
5248
*/
5349
public abstract class AbstractFallbackCacheOperationSource implements CacheOperationSource {
5450

5551
/**
56-
* Canonical value held in cache to indicate no caching attribute was
57-
* found for this method and we don't need to look again.
52+
* Canonical value held in cache to indicate no cache operation was
53+
* found for this method, and we don't need to look again.
5854
*/
59-
private static final Collection<CacheOperation> NULL_CACHING_ATTRIBUTE = Collections.emptyList();
55+
private static final Collection<CacheOperation> NULL_CACHING_MARKER = Collections.emptyList();
6056

6157

6258
/**
@@ -71,14 +67,14 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
7167
* <p>As this base class is not marked Serializable, the cache will be recreated
7268
* after serialization - provided that the concrete subclass is Serializable.
7369
*/
74-
private final Map<Object, Collection<CacheOperation>> attributeCache = new ConcurrentHashMap<>(1024);
70+
private final Map<Object, Collection<CacheOperation>> operationCache = new ConcurrentHashMap<>(1024);
7571

7672

7773
/**
78-
* Determine the caching attribute for this method invocation.
79-
* <p>Defaults to the class's caching attribute if no method attribute is found.
74+
* Determine the cache operations for this method invocation.
75+
* <p>Defaults to class-declared metadata if no method-level metadata is found.
8076
* @param method the method for the current invocation (never {@code null})
81-
* @param targetClass the target class for this invocation (may be {@code null})
77+
* @param targetClass the target class for this invocation (can be {@code null})
8278
* @return {@link CacheOperation} for this method, or {@code null} if the method
8379
* is not cacheable
8480
*/
@@ -90,21 +86,21 @@ public Collection<CacheOperation> getCacheOperations(Method method, @Nullable Cl
9086
}
9187

9288
Object cacheKey = getCacheKey(method, targetClass);
93-
Collection<CacheOperation> cached = this.attributeCache.get(cacheKey);
89+
Collection<CacheOperation> cached = this.operationCache.get(cacheKey);
9490

9591
if (cached != null) {
96-
return (cached != NULL_CACHING_ATTRIBUTE ? cached : null);
92+
return (cached != NULL_CACHING_MARKER ? cached : null);
9793
}
9894
else {
9995
Collection<CacheOperation> cacheOps = computeCacheOperations(method, targetClass);
10096
if (cacheOps != null) {
10197
if (logger.isTraceEnabled()) {
102-
logger.trace("Adding cacheable method '" + method.getName() + "' with attribute: " + cacheOps);
98+
logger.trace("Adding cacheable method '" + method.getName() + "' with operations: " + cacheOps);
10399
}
104-
this.attributeCache.put(cacheKey, cacheOps);
100+
this.operationCache.put(cacheKey, cacheOps);
105101
}
106102
else {
107-
this.attributeCache.put(cacheKey, NULL_CACHING_ATTRIBUTE);
103+
this.operationCache.put(cacheKey, NULL_CACHING_MARKER);
108104
}
109105
return cacheOps;
110106
}
@@ -129,7 +125,7 @@ private Collection<CacheOperation> computeCacheOperations(Method method, @Nullab
129125
return null;
130126
}
131127

132-
// The method may be on an interface, but we need attributes from the target class.
128+
// The method may be on an interface, but we need metadata from the target class.
133129
// If the target class is null, the method will be unchanged.
134130
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
135131

@@ -163,19 +159,19 @@ private Collection<CacheOperation> computeCacheOperations(Method method, @Nullab
163159

164160

165161
/**
166-
* Subclasses need to implement this to return the caching attribute for the
162+
* Subclasses need to implement this to return the cache operations for the
167163
* given class, if any.
168-
* @param clazz the class to retrieve the attribute for
169-
* @return all caching attribute associated with this class, or {@code null} if none
164+
* @param clazz the class to retrieve the cache operations for
165+
* @return all cache operations associated with this class, or {@code null} if none
170166
*/
171167
@Nullable
172168
protected abstract Collection<CacheOperation> findCacheOperations(Class<?> clazz);
173169

174170
/**
175-
* Subclasses need to implement this to return the caching attribute for the
171+
* Subclasses need to implement this to return the cache operations for the
176172
* given method, if any.
177-
* @param method the method to retrieve the attribute for
178-
* @return all caching attribute associated with this method, or {@code null} if none
173+
* @param method the method to retrieve the cache operations for
174+
* @return all cache operations associated with this method, or {@code null} if none
179175
*/
180176
@Nullable
181177
protected abstract Collection<CacheOperation> findCacheOperations(Method method);

spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,7 +54,7 @@ default boolean isCandidateClass(Class<?> targetClass) {
5454
* Return the collection of cache operations for this method,
5555
* or {@code null} if the method contains no <em>cacheable</em> annotations.
5656
* @param method the method to introspect
57-
* @param targetClass the target class (may be {@code null}, in which case
57+
* @param targetClass the target class (can be {@code null}, in which case
5858
* the declaring class of the method must be used)
5959
* @return all cache operations for this method, or {@code null} if none found
6060
*/

spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationSourcePointcut.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,15 +28,15 @@
2828

2929
/**
3030
* A {@code Pointcut} that matches if the underlying {@link CacheOperationSource}
31-
* has an attribute for a given method.
31+
* has an operation for a given method.
3232
*
3333
* @author Costin Leau
3434
* @author Juergen Hoeller
3535
* @author Sam Brannen
3636
* @since 3.1
3737
*/
3838
@SuppressWarnings("serial")
39-
class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {
39+
final class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable {
4040

4141
@Nullable
4242
private CacheOperationSource cacheOperationSource;
@@ -78,7 +78,7 @@ public String toString() {
7878
* {@link ClassFilter} that delegates to {@link CacheOperationSource#isCandidateClass}
7979
* for filtering classes whose methods are not worth searching to begin with.
8080
*/
81-
private class CacheOperationSourceClassFilter implements ClassFilter {
81+
private final class CacheOperationSourceClassFilter implements ClassFilter {
8282

8383
@Override
8484
public boolean matches(Class<?> clazz) {
@@ -88,14 +88,15 @@ public boolean matches(Class<?> clazz) {
8888
return (cacheOperationSource == null || cacheOperationSource.isCandidateClass(clazz));
8989
}
9090

91+
@Nullable
9192
private CacheOperationSource getCacheOperationSource() {
9293
return cacheOperationSource;
9394
}
9495

9596
@Override
9697
public boolean equals(@Nullable Object other) {
9798
return (this == other || (other instanceof CacheOperationSourceClassFilter that &&
98-
ObjectUtils.nullSafeEquals(cacheOperationSource, that.getCacheOperationSource())));
99+
ObjectUtils.nullSafeEquals(getCacheOperationSource(), that.getCacheOperationSource())));
99100
}
100101

101102
@Override
@@ -105,9 +106,8 @@ public int hashCode() {
105106

106107
@Override
107108
public String toString() {
108-
return CacheOperationSourceClassFilter.class.getName() + ": " + cacheOperationSource;
109+
return CacheOperationSourceClassFilter.class.getName() + ": " + getCacheOperationSource();
109110
}
110-
111111
}
112112

113113
}

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -98,8 +98,8 @@ public AsyncAnnotationBeanPostProcessor() {
9898
* applying the corresponding default if a supplier is not resolvable.
9999
* @since 5.1
100100
*/
101-
public void configure(
102-
@Nullable Supplier<Executor> executor, @Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) {
101+
public void configure(@Nullable Supplier<Executor> executor,
102+
@Nullable Supplier<AsyncUncaughtExceptionHandler> exceptionHandler) {
103103

104104
this.executor = executor;
105105
this.exceptionHandler = exceptionHandler;

spring-context/src/test/java/org/springframework/validation/DataBinderTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,7 +1984,7 @@ void setAutoGrowCollectionLimitAfterInitialization() {
19841984
.withMessageContaining("DataBinder is already initialized - call setAutoGrowCollectionLimit before other configuration methods");
19851985
}
19861986

1987-
@Test // SPR-15009
1987+
@Test // SPR-15009
19881988
void setCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() {
19891989
TestBean testBean = new TestBean();
19901990
DataBinder binder = new DataBinder(testBean, "testBean");
@@ -2001,7 +2001,7 @@ void setCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAc
20012001
assertThat(((BeanWrapper) binder.getInternalBindingResult().getPropertyAccessor()).getAutoGrowCollectionLimit()).isEqualTo(512);
20022002
}
20032003

2004-
@Test // SPR-15009
2004+
@Test // SPR-15009
20052005
void setCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() {
20062006
TestBean testBean = new TestBean();
20072007
DataBinder binder = new DataBinder(testBean, "testBean");
@@ -2055,7 +2055,7 @@ void callSetMessageCodesResolverTwice() {
20552055
.withMessageContaining("DataBinder is already initialized with MessageCodesResolver");
20562056
}
20572057

2058-
@Test // gh-24347
2058+
@Test // gh-24347
20592059
void overrideBindingResultType() {
20602060
TestBean testBean = new TestBean();
20612061
DataBinder binder = new DataBinder(testBean, "testBean");

0 commit comments

Comments
 (0)