Skip to content

Commit 22fc325

Browse files
committed
Polishing
1 parent 322b0f4 commit 22fc325

File tree

10 files changed

+55
-49
lines changed

10 files changed

+55
-49
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;
@@ -93,7 +92,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
9392
* List of Advisors. If an Advice is added, it will be wrapped
9493
* in an Advisor before being added to this List.
9594
*/
96-
private List<Advisor> advisors = new LinkedList<Advisor>();
95+
private List<Advisor> advisors = new ArrayList<Advisor>();
9796

9897
/**
9998
* Array updated on changes to the advisors list, which is easier
@@ -480,7 +479,7 @@ public int countAdvicesOfType(Class<?> adviceClass) {
480479
* for the given method, based on this configuration.
481480
* @param method the proxied method
482481
* @param targetClass the target class
483-
* @return List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
482+
* @return a List of MethodInterceptors (may also include InterceptorAndDynamicMethodMatchers)
484483
*/
485484
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(Method method, Class<?> targetClass) {
486485
MethodCacheKey cacheKey = new MethodCacheKey(method);
@@ -534,7 +533,7 @@ protected void copyConfigurationFrom(AdvisedSupport other, TargetSource targetSo
534533

535534
/**
536535
* Build a configuration-only copy of this AdvisedSupport,
537-
* replacing the TargetSource
536+
* replacing the TargetSource.
538537
*/
539538
AdvisedSupport getConfigurationOnlyCopy() {
540539
AdvisedSupport copy = new AdvisedSupport();

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

Lines changed: 3 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.
@@ -62,9 +62,9 @@ public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
6262
// Add it conditionally.
6363
PointcutAdvisor pointcutAdvisor = (PointcutAdvisor) advisor;
6464
if (config.isPreFiltered() || pointcutAdvisor.getPointcut().getClassFilter().matches(actualClass)) {
65-
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
6665
MethodMatcher mm = pointcutAdvisor.getPointcut().getMethodMatcher();
6766
if (MethodMatchers.matches(mm, method, actualClass, hasIntroductions)) {
67+
MethodInterceptor[] interceptors = registry.getInterceptors(advisor);
6868
if (mm.isRuntime()) {
6969
// Creating a new object instance in the getInterceptors() method
7070
// isn't a problem as we normally cache created chains.
@@ -98,8 +98,7 @@ else if (advisor instanceof IntroductionAdvisor) {
9898
* Determine whether the Advisors contain matching introductions.
9999
*/
100100
private static boolean hasMatchingIntroductions(Advised config, Class<?> actualClass) {
101-
for (int i = 0; i < config.getAdvisors().length; i++) {
102-
Advisor advisor = config.getAdvisors()[i];
101+
for (Advisor advisor : config.getAdvisors()) {
103102
if (advisor instanceof IntroductionAdvisor) {
104103
IntroductionAdvisor ia = (IntroductionAdvisor) advisor;
105104
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/test/java/org/springframework/cache/jcache/interceptor/AnnotationCacheOperationSourceTests.java

Lines changed: 3 additions & 3 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.
@@ -47,11 +47,11 @@ public class AnnotationCacheOperationSourceTests extends AbstractJCacheTests {
4747

4848
private final DefaultJCacheOperationSource source = new DefaultJCacheOperationSource();
4949

50-
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
50+
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
5151

5252

5353
@Before
54-
public void setUp() {
54+
public void setup() {
5555
source.setCacheResolver(defaultCacheResolver);
5656
source.setExceptionCacheResolver(defaultExceptionCacheResolver);
5757
source.setKeyGenerator(defaultKeyGenerator);

spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java

Lines changed: 3 additions & 3 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.
@@ -37,12 +37,12 @@ public CacheManager cacheManager() {
3737
}
3838

3939
@Override
40-
public KeyGenerator keyGenerator() {
40+
public CacheResolver cacheResolver() {
4141
return null;
4242
}
4343

4444
@Override
45-
public CacheResolver cacheResolver() {
45+
public KeyGenerator keyGenerator() {
4646
return null;
4747
}
4848

spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java

Lines changed: 10 additions & 10 deletions
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.
@@ -110,21 +110,21 @@ private void registerCacheAdvisor(Element element, ParserContext parserContext)
110110
*/
111111
private static void parseCacheResolution(Element element, BeanDefinition def, boolean setBoth) {
112112
String name = element.getAttribute("cache-resolver");
113-
if (StringUtils.hasText(name)) {
113+
boolean hasText = StringUtils.hasText(name);
114+
if (hasText) {
114115
def.getPropertyValues().add("cacheResolver", new RuntimeBeanReference(name.trim()));
115116
}
116-
if (!StringUtils.hasText(name) || setBoth) {
117+
if (!hasText || setBoth) {
117118
def.getPropertyValues().add("cacheManager",
118119
new RuntimeBeanReference(CacheNamespaceHandler.extractCacheManager(element)));
119120
}
120121
}
121122

122-
private static BeanDefinition parseErrorHandler(Element element, BeanDefinition def) {
123+
private static void parseErrorHandler(Element element, BeanDefinition def) {
123124
String name = element.getAttribute("error-handler");
124125
if (StringUtils.hasText(name)) {
125126
def.getPropertyValues().add("errorHandler", new RuntimeBeanReference(name.trim()));
126127
}
127-
return def;
128128
}
129129

130130

@@ -173,12 +173,12 @@ private static void registerCacheAdvisor(Element element, ParserContext parserCo
173173
}
174174

175175
/**
176-
* Registers a
176+
* Registers a cache aspect.
177177
* <pre class="code">
178-
* <bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf">
179-
* <property name="cacheManager" ref="cacheManager"/>
180-
* <property name="keyGenerator" ref="keyGenerator"/>
181-
* </bean>
178+
* &lt;bean id="cacheAspect" class="org.springframework.cache.aspectj.AnnotationCacheAspect" factory-method="aspectOf"&gt;
179+
* &lt;property name="cacheManager" ref="cacheManager"/&gt;
180+
* &lt;property name="keyGenerator" ref="keyGenerator"/&gt;
181+
* &lt;/bean&gt;
182182
* </pre>
183183
*/
184184
private static void registerCacheAspect(Element element, ParserContext parserContext) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ public void afterSingletonsInstantiated() {
207207
}
208208
catch (NoUniqueBeanDefinitionException ex) {
209209
throw new IllegalStateException("No CacheResolver specified, and no unique bean of type " +
210-
"CacheManager found. Mark one as primary (or give it the name 'cacheManager') or " +
211-
"declare a specific CacheManager to use, that serves as the default one.");
210+
"CacheManager found. Mark one as primary or declare a specific CacheManager to use.");
212211
}
213212
catch (NoSuchBeanDefinitionException ex) {
214213
throw new IllegalStateException("No CacheResolver specified, and no bean of type CacheManager found. " +
@@ -651,6 +650,9 @@ public CacheOperationMetadata(CacheOperation operation, Method method, Class<?>
651650
}
652651

653652

653+
/**
654+
* A {@link CacheOperationInvocationContext} context for a {@link CacheOperation}.
655+
*/
654656
protected class CacheOperationContext implements CacheOperationInvocationContext<CacheOperation> {
655657

656658
private final CacheOperationMetadata metadata;

spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,9 @@ private Reference<K, V> findInChain(Reference<K, V> ref, Object key, int hash) {
619619
return null;
620620
}
621621

622-
@SuppressWarnings("unchecked")
622+
@SuppressWarnings({"rawtypes", "unchecked"})
623623
private Reference<K, V>[] createReferenceArray(int size) {
624-
return (Reference<K, V>[]) Array.newInstance(Reference.class, size);
624+
return new Reference[size];
625625
}
626626

627627
private int getIndex(int hash, Reference<K, V>[] references) {
@@ -756,8 +756,8 @@ public boolean hasOption(TaskOption option) {
756756

757757
/**
758758
* Execute the task.
759-
* @param ref the found reference or {@code null}
760-
* @param entry the found entry or {@code null}
759+
* @param ref the found reference (or {@code null})
760+
* @param entry the found entry (or {@code null})
761761
* @param entries access to the underlying entries
762762
* @return the result of the task
763763
* @see #execute(Reference, Entry)
@@ -768,8 +768,8 @@ protected T execute(Reference<K, V> ref, Entry<K, V> entry, Entries entries) {
768768

769769
/**
770770
* Convenience method that can be used for tasks that do not need access to {@link Entries}.
771-
* @param ref the found reference or {@code null}
772-
* @param entry the found entry or {@code null}
771+
* @param ref the found reference (or {@code null})
772+
* @param entry the found entry (or {@code null})
773773
* @return the result of the task
774774
* @see #execute(Reference, Entry, Entries)
775775
*/

spring-core/src/test/java/org/springframework/core/annotation/OrderUtilsTests.java

Lines changed: 9 additions & 2 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.
@@ -23,41 +23,48 @@
2323
import static org.junit.Assert.*;
2424

2525
/**
26-
*
2726
* @author Stephane Nicoll
27+
* @author Juergen Hoeller
2828
*/
2929
public class OrderUtilsTests {
3030

3131
@Test
3232
public void getSimpleOrder() {
3333
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(SimpleOrder.class, null));
34+
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(SimpleOrder.class, null));
3435
}
3536

3637
@Test
3738
public void getPriorityOrder() {
3839
assertEquals(Integer.valueOf(55), OrderUtils.getOrder(SimplePriority.class, null));
40+
assertEquals(Integer.valueOf(55), OrderUtils.getOrder(SimplePriority.class, null));
3941
}
4042

4143
@Test
4244
public void getOrderWithBoth() {
4345
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(OrderAndPriority.class, null));
46+
assertEquals(Integer.valueOf(50), OrderUtils.getOrder(OrderAndPriority.class, null));
4447
}
4548

4649
@Test
4750
public void getDefaultOrder() {
4851
assertEquals(Integer.valueOf(33), OrderUtils.getOrder(NoOrder.class, 33));
52+
assertEquals(Integer.valueOf(33), OrderUtils.getOrder(NoOrder.class, 33));
4953
}
5054

5155
@Test
5256
public void getPriorityValueNoAnnotation() {
5357
assertNull(OrderUtils.getPriority(SimpleOrder.class));
58+
assertNull(OrderUtils.getPriority(SimpleOrder.class));
5459
}
5560

5661
@Test
5762
public void getPriorityValue() {
5863
assertEquals(Integer.valueOf(55), OrderUtils.getPriority(OrderAndPriority.class));
64+
assertEquals(Integer.valueOf(55), OrderUtils.getPriority(OrderAndPriority.class));
5965
}
6066

67+
6168
@Order(50)
6269
private static class SimpleOrder {}
6370

0 commit comments

Comments
 (0)