Skip to content

Commit 2ae2249

Browse files
committed
Polishing
1 parent 484addb commit 2ae2249

File tree

4 files changed

+37
-32
lines changed

4 files changed

+37
-32
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@
3131
import java.util.HashSet;
3232
import java.util.Iterator;
3333
import java.util.LinkedHashSet;
34-
import java.util.LinkedList;
3534
import java.util.List;
36-
import java.util.Map;
3735
import java.util.Set;
3836
import java.util.TreeSet;
3937
import java.util.concurrent.ConcurrentHashMap;
@@ -146,7 +144,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
146144
private final Set<Class<?>> ignoredDependencyInterfaces = new HashSet<Class<?>>();
147145

148146
/** Cache of unfinished FactoryBean instances: FactoryBean name --> BeanWrapper */
149-
private final Map<String, BeanWrapper> factoryBeanInstanceCache =
147+
private final ConcurrentMap<String, BeanWrapper> factoryBeanInstanceCache =
150148
new ConcurrentHashMap<String, BeanWrapper>(16);
151149

152150
/** Cache of filtered PropertyDescriptors: bean Class -> PropertyDescriptor array */
@@ -1422,7 +1420,7 @@ protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanW
14221420
*/
14231421
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw) {
14241422
List<PropertyDescriptor> pds =
1425-
new LinkedList<PropertyDescriptor>(Arrays.asList(bw.getPropertyDescriptors()));
1423+
new ArrayList<PropertyDescriptor>(Arrays.asList(bw.getPropertyDescriptors()));
14261424
for (Iterator<PropertyDescriptor> it = pds.iterator(); it.hasNext();) {
14271425
PropertyDescriptor pd = it.next();
14281426
if (isExcludedFromDependencyCheck(pd)) {

spring-beans/src/test/java/org/springframework/beans/factory/annotation/InjectAnnotationBeanPostProcessorTests.java

Lines changed: 12 additions & 14 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.
@@ -45,7 +45,7 @@
4545

4646
/**
4747
* Unit tests for {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor}
48-
* processing the JSR-303 {@link javax.inject.Inject} annotation.
48+
* processing the JSR-330 {@link javax.inject.Inject} annotation.
4949
*
5050
* @author Juergen Hoeller
5151
* @since 3.0
@@ -548,11 +548,9 @@ public void testObjectFactoryWithTypedMapMethod() throws Exception {
548548
}
549549

550550
/**
551-
* Verifies that a dependency on a {@link org.springframework.beans.factory.FactoryBean} can be autowired via
552-
* {@link org.springframework.beans.factory.annotation.Autowired @Inject}, specifically addressing the JIRA issue
553-
* raised in <a
554-
* href="http://opensource.atlassian.com/projects/spring/browse/SPR-4040"
555-
* target="_blank">SPR-4040</a>.
551+
* Verifies that a dependency on a {@link org.springframework.beans.factory.FactoryBean}
552+
* can be autowired via {@link org.springframework.beans.factory.annotation.Autowired @Inject},
553+
* specifically addressing SPR-4040.
556554
*/
557555
@Test
558556
public void testBeanAutowiredWithFactoryBean() {
@@ -1259,7 +1257,7 @@ public final FactoryBean<?> getFactoryBean() {
12591257
public static class StringFactoryBean implements FactoryBean<String> {
12601258

12611259
@Override
1262-
public String getObject() throws Exception {
1260+
public String getObject() {
12631261
return "";
12641262
}
12651263

@@ -1291,8 +1289,8 @@ public static class OptionalMethodInjectionBean {
12911289
private Optional<TestBean> testBean;
12921290

12931291
@Inject
1294-
public void setTestBean(Optional<TestBean> testBeanFactory) {
1295-
this.testBean = testBeanFactory;
1292+
public void setTestBean(Optional<TestBean> testBean) {
1293+
this.testBean = testBean;
12961294
}
12971295

12981296
public Optional<TestBean> getTestBean() {
@@ -1317,8 +1315,8 @@ public static class OptionalListMethodInjectionBean {
13171315
private Optional<List<TestBean>> testBean;
13181316

13191317
@Inject
1320-
public void setTestBean(Optional<List<TestBean>> testBeanFactory) {
1321-
this.testBean = testBeanFactory;
1318+
public void setTestBean(Optional<List<TestBean>> testBean) {
1319+
this.testBean = testBean;
13221320
}
13231321

13241322
public Optional<List<TestBean>> getTestBean() {
@@ -1343,8 +1341,8 @@ public static class ProviderOfOptionalMethodInjectionBean {
13431341
private Provider<Optional<TestBean>> testBean;
13441342

13451343
@Inject
1346-
public void setTestBean(Provider<Optional<TestBean>> testBeanFactory) {
1347-
this.testBean = testBeanFactory;
1344+
public void setTestBean(Provider<Optional<TestBean>> testBean) {
1345+
this.testBean = testBean;
13481346
}
13491347

13501348
public Optional<TestBean> getTestBean() {

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

Lines changed: 18 additions & 11 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.
@@ -31,16 +31,25 @@
3131
* invocation context.
3232
*
3333
* @author Stephane Nicoll
34+
* @author Juergen Hoeller
3435
* @since 4.1
3536
*/
3637
public abstract class AbstractCacheResolver implements CacheResolver, InitializingBean {
3738

3839
private CacheManager cacheManager;
3940

4041

42+
/**
43+
* Construct a new {@code AbstractCacheResolver}.
44+
* @see #setCacheManager
45+
*/
4146
protected AbstractCacheResolver() {
4247
}
4348

49+
/**
50+
* Construct a new {@code AbstractCacheResolver} for the given {@link CacheManager}.
51+
* @param cacheManager the CacheManager to use
52+
*/
4453
protected AbstractCacheResolver(CacheManager cacheManager) {
4554
this.cacheManager = cacheManager;
4655
}
@@ -72,18 +81,16 @@ public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext
7281
if (cacheNames == null) {
7382
return Collections.emptyList();
7483
}
75-
else {
76-
Collection<Cache> result = new ArrayList<Cache>();
77-
for (String cacheName : cacheNames) {
78-
Cache cache = getCacheManager().getCache(cacheName);
79-
if (cache == null) {
80-
throw new IllegalArgumentException("Cannot find cache named '" +
81-
cacheName + "' for " + context.getOperation());
82-
}
83-
result.add(cache);
84+
Collection<Cache> result = new ArrayList<Cache>(cacheNames.size());
85+
for (String cacheName : cacheNames) {
86+
Cache cache = getCacheManager().getCache(cacheName);
87+
if (cache == null) {
88+
throw new IllegalArgumentException("Cannot find cache named '" +
89+
cacheName + "' for " + context.getOperation());
8490
}
85-
return result;
91+
result.add(cache);
8692
}
93+
return result;
8794
}
8895

8996
/**

spring-web/src/main/java/org/springframework/http/client/OkHttp3ClientHttpRequestFactory.java

Lines changed: 5 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.
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.concurrent.TimeUnit;
2525

26+
import okhttp3.Cache;
2627
import okhttp3.OkHttpClient;
2728
import okhttp3.Request;
2829
import okhttp3.RequestBody;
@@ -118,8 +119,9 @@ public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
118119
public void destroy() throws IOException {
119120
if (this.defaultClient) {
120121
// Clean up the client if we created it in the constructor
121-
if (this.client.cache() != null) {
122-
this.client.cache().close();
122+
Cache cache = this.client.cache();
123+
if (cache != null) {
124+
cache.close();
123125
}
124126
this.client.dispatcher().executorService().shutdown();
125127
}

0 commit comments

Comments
 (0)