Skip to content

Commit c0040a5

Browse files
committed
Polishing
1 parent 55563c1 commit c0040a5

File tree

52 files changed

+324
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+324
-246
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.ArrayList;
2323
import java.util.Arrays;
2424
import java.util.Collection;
25-
import java.util.LinkedList;
2625
import java.util.List;
2726
import java.util.Map;
2827
import java.util.concurrent.ConcurrentHashMap;
@@ -94,7 +93,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
9493
* List of Advisors. If an Advice is added, it will be wrapped
9594
* in an Advisor before being added to this List.
9695
*/
97-
private List<Advisor> advisors = new LinkedList<>();
96+
private List<Advisor> advisors = new ArrayList<>();
9897

9998
/**
10099
* Array updated on changes to the advisors list, which is easier
@@ -474,7 +473,7 @@ public int countAdvicesOfType(@Nullable Class<?> adviceClass) {
474473
* for the given method, based on this configuration.
475474
* @param method the proxied method
476475
* @param targetClass the target class
477-
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
476+
* @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
478477
*/
479478
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, @Nullable Class<?> targetClass) {
480479
MethodCacheKey cacheKey = new MethodCacheKey(method);
@@ -528,7 +527,7 @@ protected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSo
528527

529528
/**
530529
* Build a configuration-only copy of this AdvisedSupport,
531-
* replacing the TargetSource
530+
* replacing the TargetSource.
532531
*/
533532
AdvisedSupport getConfigurationOnlyCopy() {
534533
AdvisedSupport copy = new AdvisedSupport();

spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -27,11 +27,11 @@
2727

2828
import org.springframework.aop.Advisor;
2929
import org.springframework.aop.IntroductionAdvisor;
30+
import org.springframework.aop.IntroductionAwareMethodMatcher;
3031
import org.springframework.aop.MethodMatcher;
3132
import org.springframework.aop.PointcutAdvisor;
3233
import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry;
3334
import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry;
34-
import org.springframework.aop.support.MethodMatchers;
3535
import org.springframework.lang.Nullable;
3636

3737
/**
@@ -53,19 +53,30 @@ public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
5353

5454
// This is somewhat tricky... We have to process introductions first,
5555
// but we need to preserve order in the ultimate list.
56-
List<Object> interceptorList = new ArrayList<>(config.getAdvisors().length);
57-
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass());
58-
boolean hasIntroductions = hasMatchingIntroductions(config, actualClass);
5956
AdvisorAdapterRegistry registry = GlobalAdvisorAdapterRegistry.getInstance();
57+
Advisor[] advisors = config.getAdvisors();
58+
List<Object> interceptorList = new ArrayList<>(advisors.length);
59+
Class<?> actualClass = (targetClass != null ? targetClass : method.getDeclaringClass());
60+
Boolean hasIntroductions = null;
6061

61-
for (Advisor advisor : config.getAdvisors()) {
62+
for (Advisor advisor : advisors) {
6263
if (advisor instanceof PointcutAdvisor) {
6364
// Add it conditionally.
6465
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
6566
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
66-
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
6767
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
68-
if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
68+
boolean match;
69+
if (mm instanceof IntroductionAwareMethodMatcher) {
70+
if (hasIntroductions == null) {
71+
hasIntroductions = hasMatchingIntroductions(advisors, actualClass);
72+
}
73+
match = ((IntroductionAwareMethodMatcher) mm).matches(method, targetClass, hasIntroductions);
74+
}
75+
else {
76+
match = mm.matches(method, targetClass);
77+
}
78+
if (match) {
79+
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
6980
if (mm.isRuntime()) {
7081
// Creating a new object instance in the getInterceptors() method
7182
// isn't a problem as we normally cache created chains.
@@ -98,9 +109,8 @@ else if (advisor instanceof IntroductionAdvisor) {
98109
/**
99110
* Determine whether the Advisors contain matching introductions.
100111
*/
101-
private static boolean hasMatchingIntroductions(Advised config, Class<?> actualClass) {
102-
for (int i = 0; i < config.getAdvisors().length; i++) {
103-
Advisor advisor = config.getAdvisors()[i];
112+
private static boolean hasMatchingIntroductions(Advisor[] advisors, Class<?> actualClass) {
113+
for (Advisor advisor : advisors) {
104114
if (advisor instanceof IntroductionAdvisor) {
105115
IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
106116
if (ia.getClassFilter().matches(actualClass)) {

spring-aop/src/main/java/org/springframework/aop/framework/adapter/AdvisorAdapterRegistry.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -31,15 +31,15 @@
3131
public interface AdvisorAdapterRegistry {
3232

3333
/**
34-
* Return an Advisor wrapping the given advice.
34+
* Return an {@link Advisor} wrapping the given advice.
3535
* <p>Should by default at least support
3636
* {@link org.aopalliance.intercept.MethodInterceptor},
3737
* {@link org.springframework.aop.MethodBeforeAdvice},
3838
* {@link org.springframework.aop.AfterReturningAdvice},
3939
* {@link org.springframework.aop.ThrowsAdvice}.
4040
* @param advice object that should be an advice
41-
* @return an Advisor wrapping the given advice. Never returns {@code null}.
42-
* If the advice parameter is an Advisor, return it.
41+
* @return an Advisor wrapping the given advice (never {@code null};
42+
* if the advice parameter is an Advisor, it is to be returned as-is)
4343
* @throws UnknownAdviceTypeException if no registered advisor adapter
4444
* can wrap the supposed advice
4545
*/
@@ -48,21 +48,20 @@ public interface AdvisorAdapterRegistry {
4848
/**
4949
* Return an array of AOP Alliance MethodInterceptors to allow use of the
5050
* given Advisor in an interception-based framework.
51-
* <p>Don't worry about the pointcut associated with the Advisor,
52-
* if it's a PointcutAdvisor: just return an interceptor.
51+
* <p>Don't worry about the pointcut associated with the {@link Advisor}, if it is
52+
* a {@link org.springframework.aop.PointcutAdvisor}: just return an interceptor.
5353
* @param advisor Advisor to find an interceptor for
5454
* @return an array of MethodInterceptors to expose this Advisor's behavior
5555
* @throws UnknownAdviceTypeException if the Advisor type is
56-
* not understood by any registered AdvisorAdapter.
56+
* not understood by any registered AdvisorAdapter
5757
*/
5858
MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException;
5959

6060
/**
61-
* Register the given AdvisorAdapter. Note that it is not necessary to register
61+
* Register the given {@link AdvisorAdapter}. Note that it is not necessary to register
6262
* adapters for an AOP Alliance Interceptors or Spring Advices: these must be
63-
* automatically recognized by an AdvisorAdapterRegistry implementation.
64-
* @param adapter AdvisorAdapter that understands a particular Advisor
65-
* or Advice types
63+
* automatically recognized by an {@code AdvisorAdapterRegistry} implementation.
64+
* @param adapter AdvisorAdapter that understands particular Advisor or Advice types
6665
*/
6766
void registerAdvisorAdapter(AdvisorAdapter adapter);
6867

spring-aop/src/main/java/org/springframework/aop/interceptor/SimpleAsyncUncaughtExceptionHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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,13 +29,13 @@
2929
*/
3030
public class SimpleAsyncUncaughtExceptionHandler implements AsyncUncaughtExceptionHandler {
3131

32-
private final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class);
32+
private static final Log logger = LogFactory.getLog(SimpleAsyncUncaughtExceptionHandler.class);
33+
3334

3435
@Override
3536
public void handleUncaughtException(Throwable ex, Method method, Object... params) {
3637
if (logger.isErrorEnabled()) {
37-
logger.error(String.format("Unexpected error occurred invoking async " +
38-
"method '%s'.", method), ex);
38+
logger.error("Unexpected error occurred invoking async method: " + method, ex);
3939
}
4040
}
4141

spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -25,6 +25,7 @@
2525
import org.springframework.context.annotation.Bean;
2626
import org.springframework.context.annotation.Configuration;
2727
import org.springframework.context.annotation.Role;
28+
import org.springframework.lang.Nullable;
2829

2930
/**
3031
* Abstract JSR-107 specific {@code @Configuration} class providing common
@@ -37,8 +38,10 @@
3738
@Configuration
3839
public class AbstractJCacheConfiguration extends AbstractCachingConfiguration {
3940

41+
@Nullable
4042
protected CacheResolver exceptionCacheResolver;
4143

44+
4245
@Override
4346
protected void useCachingConfigurer(CachingConfigurer config) {
4447
super.useCachingConfigurer(config);

spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.cache.annotation.CachingConfigurer;
2020
import org.springframework.cache.interceptor.CacheResolver;
21+
import org.springframework.lang.Nullable;
2122

2223
/**
2324
* Extension of {@link CachingConfigurer} for the JSR-107 implementation.
@@ -58,6 +59,7 @@ public interface JCacheConfigurer extends CachingConfigurer {
5859
* </pre>
5960
* See {@link org.springframework.cache.annotation.EnableCaching} for more complete examples.
6061
*/
62+
@Nullable
6163
CacheResolver exceptionCacheResolver();
6264

6365
}

spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurerSupport.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.cache.annotation.CachingConfigurerSupport;
2020
import org.springframework.cache.interceptor.CacheResolver;
21+
import org.springframework.lang.Nullable;
2122

2223
/**
2324
* An extension of {@link CachingConfigurerSupport} that also implements
@@ -34,6 +35,7 @@
3435
public class JCacheConfigurerSupport extends CachingConfigurerSupport implements JCacheConfigurer {
3536

3637
@Override
38+
@Nullable
3739
public CacheResolver exceptionCacheResolver() {
3840
return null;
3941
}

spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
* <p>Provide an extension of the {@code CachingConfigurer} that exposes
77
* the exception cache resolver to use, see {@code JCacheConfigurer}.
88
*/
9+
@NonNullApi
10+
@NonNullFields
911
package org.springframework.cache.jcache.config;
12+
13+
import org.springframework.lang.NonNullApi;
14+
import org.springframework.lang.NonNullFields;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -49,6 +49,7 @@ protected AbstractCacheInterceptor(CacheErrorHandler errorHandler) {
4949
}
5050

5151

52+
@Nullable
5253
protected abstract Object invoke(CacheOperationInvocationContext<O> context, CacheOperationInvoker invoker)
5354
throws Throwable;
5455

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe
5555

5656

5757
@Override
58-
public JCacheOperation<?> getCacheOperation(Method method, Class<?> targetClass) {
58+
public JCacheOperation<?> getCacheOperation(Method method, @Nullable Class<?> targetClass) {
5959
MethodClassKey cacheKey = new MethodClassKey(method, targetClass);
6060
Object cached = this.cache.get(cacheKey);
6161

@@ -78,7 +78,7 @@ public JCacheOperation<?> getCacheOperation(Method method, Class<?> targetClass)
7878
}
7979

8080
@Nullable
81-
private JCacheOperation<?> computeCacheOperation(Method method, Class<?> targetClass) {
81+
private JCacheOperation<?> computeCacheOperation(Method method, @Nullable Class<?> targetClass) {
8282
// Don't allow no-public methods as required.
8383
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
8484
return null;
@@ -113,7 +113,7 @@ private JCacheOperation<?> computeCacheOperation(Method method, Class<?> targetC
113113
* (or {@code null} if none)
114114
*/
115115
@Nullable
116-
protected abstract JCacheOperation<?> findCacheOperation(Method method, Class<?> targetType);
116+
protected abstract JCacheOperation<?> findCacheOperation(Method method, @Nullable Class<?> targetType);
117117

118118
/**
119119
* Should only public methods be allowed to have caching semantics?

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp
5050

5151

5252
/**
53-
* Create a new instance.
53+
* Construct a new {@code AbstractJCacheOperation}.
5454
* @param methodDetails the {@link CacheMethodDetails} related to the cached method
5555
* @param cacheResolver the cache resolver to resolve regular caches
5656
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -37,6 +37,7 @@ protected AbstractKeyCacheInterceptor(CacheErrorHandler errorHandler) {
3737
super(errorHandler);
3838
}
3939

40+
4041
/**
4142
* Generate a key for the specified invocation.
4243
* @param context the context of the invocation
@@ -56,8 +57,7 @@ protected Object generateKey(CacheOperationInvocationContext<O> context) {
5657
* @param context the context of the invocation.
5758
* @return the related {@code CacheKeyInvocationContext}
5859
*/
59-
protected CacheKeyInvocationContext<A> createCacheKeyInvocationContext(
60-
CacheOperationInvocationContext<O> context) {
60+
protected CacheKeyInvocationContext<A> createCacheKeyInvocationContext(CacheOperationInvocationContext<O> context) {
6161
return new DefaultCacheKeyInvocationContext<>(context.getOperation(), context.getTarget(), context.getArgs());
6262
}
6363

0 commit comments

Comments
 (0)