Skip to content

Commit 04a2cd4

Browse files
committed
Polishing
1 parent b904d52 commit 04a2cd4

File tree

10 files changed

+57
-66
lines changed

10 files changed

+57
-66
lines changed

spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java

Lines changed: 5 additions & 4 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-2020 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.
@@ -148,11 +148,12 @@ public interface ConfigurableApplicationContext extends ApplicationContext, Life
148148
void addProtocolResolver(ProtocolResolver resolver);
149149

150150
/**
151-
* Load or refresh the persistent representation of the configuration,
152-
* which might an XML file, properties file, or relational database schema.
151+
* Load or refresh the persistent representation of the configuration, which
152+
* might be from Java-based configuration, an XML file, a properties file, a
153+
* relational database schema, or some other format.
153154
* <p>As this is a startup method, it should destroy already created singletons
154155
* if it fails, to avoid dangling resources. In other words, after invocation
155-
* of that method, either all or no singletons at all should be instantiated.
156+
* of this method, either all or no singletons at all should be instantiated.
156157
* @throws BeansException if the bean factory could not be initialized
157158
* @throws IllegalStateException if already initialized and multiple refresh
158159
* attempts are not supported

spring-context/src/main/java/org/springframework/ejb/config/AbstractJndiLocatingBeanDefinitionParser.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2007 the original author or authors.
2+
* Copyright 2002-2020 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,9 @@
2424
import org.springframework.util.StringUtils;
2525
import org.springframework.util.xml.DomUtils;
2626

27-
import static org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.*;
27+
import static org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.DEFAULT_VALUE;
28+
import static org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.LAZY_INIT_ATTRIBUTE;
29+
import static org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.TRUE_VALUE;
2830

2931
/**
3032
* Abstract base class for BeanDefinitionParsers which build
@@ -47,8 +49,9 @@ abstract class AbstractJndiLocatingBeanDefinitionParser extends AbstractSimpleBe
4749

4850
@Override
4951
protected boolean isEligibleAttribute(String attributeName) {
50-
return (super.isEligibleAttribute(attributeName) && !ENVIRONMENT_REF.equals(attributeName) && !LAZY_INIT_ATTRIBUTE
51-
.equals(attributeName));
52+
return (super.isEligibleAttribute(attributeName) &&
53+
!ENVIRONMENT_REF.equals(attributeName) &&
54+
!LAZY_INIT_ATTRIBUTE.equals(attributeName));
5255
}
5356

5457
@Override

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java

Lines changed: 6 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-2020 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.
@@ -43,12 +43,11 @@
4343
*/
4444
public class GenericCallMetaDataProvider implements CallMetaDataProvider {
4545

46-
/** Logger available to subclasses */
46+
/** Logger available to subclasses. */
4747
protected static final Log logger = LogFactory.getLog(CallMetaDataProvider.class);
4848

49-
private boolean procedureColumnMetaDataUsed = false;
5049

51-
private String userName;
50+
private final String userName;
5251

5352
private boolean supportsCatalogsInProcedureCalls = true;
5453

@@ -58,7 +57,9 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
5857

5958
private boolean storesLowerCaseIdentifiers = false;
6059

61-
private List<CallParameterMetaData> callParameterMetaData = new ArrayList<>();
60+
private boolean procedureColumnMetaDataUsed = false;
61+
62+
private final List<CallParameterMetaData> callParameterMetaData = new ArrayList<>();
6263

6364

6465
/**

spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistration.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.reactive.config;
1818

19-
import java.util.ArrayList;
2019
import java.util.Arrays;
2120

2221
import org.springframework.web.cors.CorsConfiguration;
@@ -28,6 +27,7 @@
2827
* @author Sebastien Deleuze
2928
* @author Rossen Stoyanchev
3029
* @since 5.0
30+
* @see CorsConfiguration
3131
* @see CorsRegistry
3232
*/
3333
public class CorsRegistration {
@@ -39,6 +39,7 @@ public class CorsRegistration {
3939

4040
public CorsRegistration(String pathPattern) {
4141
this.pathPattern = pathPattern;
42+
// Same implicit default values as the @CrossOrigin annotation + allows simple methods
4243
this.config = new CorsConfiguration().applyPermitDefaultValues();
4344
}
4445

@@ -58,7 +59,7 @@ public CorsRegistration(String pathPattern) {
5859
* See the Spring Framework reference for more on this filter.
5960
*/
6061
public CorsRegistration allowedOrigins(String... origins) {
61-
this.config.setAllowedOrigins(new ArrayList<>(Arrays.asList(origins)));
62+
this.config.setAllowedOrigins(Arrays.asList(origins));
6263
return this;
6364
}
6465

@@ -69,7 +70,7 @@ public CorsRegistration allowedOrigins(String... origins) {
6970
* are allowed.
7071
*/
7172
public CorsRegistration allowedMethods(String... methods) {
72-
this.config.setAllowedMethods(new ArrayList<>(Arrays.asList(methods)));
73+
this.config.setAllowedMethods(Arrays.asList(methods));
7374
return this;
7475
}
7576

@@ -83,7 +84,7 @@ public CorsRegistration allowedMethods(String... methods) {
8384
* <p>By default all headers are allowed.
8485
*/
8586
public CorsRegistration allowedHeaders(String... headers) {
86-
this.config.setAllowedHeaders(new ArrayList<>(Arrays.asList(headers)));
87+
this.config.setAllowedHeaders(Arrays.asList(headers));
8788
return this;
8889
}
8990

@@ -96,7 +97,7 @@ public CorsRegistration allowedHeaders(String... headers) {
9697
* <p>By default this is not set.
9798
*/
9899
public CorsRegistration exposedHeaders(String... headers) {
99-
this.config.setExposedHeaders(new ArrayList<>(Arrays.asList(headers)));
100+
this.config.setExposedHeaders(Arrays.asList(headers));
100101
return this;
101102
}
102103

spring-webflux/src/main/java/org/springframework/web/reactive/config/CorsRegistry.java

Lines changed: 9 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-2020 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,25 +37,23 @@ public class CorsRegistry {
3737

3838

3939
/**
40-
* Enable cross origin request handling for the specified path pattern.
41-
*
40+
* Enable cross-origin request handling for the specified path pattern.
4241
* <p>Exact path mapping URIs (such as {@code "/admin"}) are supported as
4342
* well as Ant-style path patterns (such as {@code "/admin/**"}).
44-
*
45-
* <p>The following defaults are applied to the {@link CorsRegistration}:
46-
* <ul>
47-
* <li>Allow all origins.</li>
48-
* <li>Allow "simple" methods {@code GET}, {@code HEAD} and {@code POST}.</li>
49-
* <li>Allow all headers.</li>
50-
* <li>Set max age to 1800 seconds (30 minutes).</li>
51-
* </ul>
43+
* <p>By default, the {@code CorsConfiguration} for this mapping is
44+
* initialized with default values as described in
45+
* {@link CorsConfiguration#applyPermitDefaultValues()}.
5246
*/
5347
public CorsRegistration addMapping(String pathPattern) {
5448
CorsRegistration registration = new CorsRegistration(pathPattern);
5549
this.registrations.add(registration);
5650
return registration;
5751
}
5852

53+
/**
54+
* Return the registered {@link CorsConfiguration} objects,
55+
* keyed by path pattern.
56+
*/
5957
protected Map<String, CorsConfiguration> getCorsConfigurations() {
6058
Map<String, CorsConfiguration> configs = new LinkedHashMap<>(this.registrations.size());
6159
for (CorsRegistration registration : this.registrations) {

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java

Lines changed: 3 additions & 5 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-2020 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.
@@ -83,7 +83,7 @@ class ControllerMethodResolver {
8383
AnnotationUtils.findAnnotation(method, ModelAttribute.class) != null);
8484

8585

86-
private static Log logger = LogFactory.getLog(ControllerMethodResolver.class);
86+
private static final Log logger = LogFactory.getLog(ControllerMethodResolver.class);
8787

8888
private final List<SyncHandlerMethodArgumentResolver> initBinderResolvers;
8989

@@ -95,14 +95,12 @@ class ControllerMethodResolver {
9595

9696
private final ReactiveAdapterRegistry reactiveAdapterRegistry;
9797

98-
9998
private final Map<Class<?>, Set<Method>> initBinderMethodCache = new ConcurrentHashMap<>(64);
10099

101100
private final Map<Class<?>, Set<Method>> modelAttributeMethodCache = new ConcurrentHashMap<>(64);
102101

103102
private final Map<Class<?>, ExceptionHandlerMethodResolver> exceptionHandlerCache = new ConcurrentHashMap<>(64);
104103

105-
106104
private final Map<ControllerAdviceBean, Set<Method>> initBinderAdviceCache = new LinkedHashMap<>(64);
107105

108106
private final Map<ControllerAdviceBean, Set<Method>> modelAttributeAdviceCache = new LinkedHashMap<>(64);
@@ -169,7 +167,7 @@ private static List<HandlerMethodArgumentResolver> initResolvers(ArgumentResolve
169167
boolean requestMappingMethod = !readers.isEmpty() && supportDataBinding;
170168

171169
// Annotation-based...
172-
List<HandlerMethodArgumentResolver> result = new ArrayList<>();
170+
List<HandlerMethodArgumentResolver> result = new ArrayList<>(30);
173171
result.add(new RequestParamMethodArgumentResolver(beanFactory, adapterRegistry, false));
174172
result.add(new RequestParamMapMethodArgumentResolver(adapterRegistry));
175173
result.add(new PathVariableMethodArgumentResolver(beanFactory, adapterRegistry));

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestAttributeMethodArgumentResolver.java

Lines changed: 1 addition & 2 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-2020 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.
@@ -38,7 +38,6 @@
3838
*/
3939
public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueSyncArgumentResolver {
4040

41-
4241
/**
4342
* @param factory a bean factory to use for resolving ${...}
4443
* placeholder and #{...} SpEL expressions in default values;

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,19 @@ public CorsRegistration allowedOrigins(String... origins) {
6767

6868
/**
6969
* Set the HTTP methods to allow, e.g. {@code "GET"}, {@code "POST"}, etc.
70-
* The special value {@code "*"} allows all methods.
71-
* <p>By default "simple" methods, i.e. {@code GET}, {@code HEAD}, and
72-
* {@code POST} are allowed.
70+
* <p>The special value {@code "*"} allows all methods.
71+
* <p>By default "simple" methods {@code GET}, {@code HEAD}, and {@code POST}
72+
* are allowed.
7373
*/
7474
public CorsRegistration allowedMethods(String... methods) {
7575
this.config.setAllowedMethods(Arrays.asList(methods));
7676
return this;
7777
}
7878

7979
/**
80-
* Set the list of headers that a preflight request can list as allowed
81-
* for use during an actual request. The special value {@code "*"} may be
82-
* used to allow all headers.
80+
* Set the list of headers that a pre-flight request can list as allowed
81+
* for use during an actual request.
82+
* <p>The special value {@code "*"} may be used to allow all headers.
8383
* <p>A header name is not required to be listed if it is one of:
8484
* {@code Cache-Control}, {@code Content-Language}, {@code Expires},
8585
* {@code Last-Modified}, or {@code Pragma} as per the CORS spec.

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/CorsRegistry.java

Lines changed: 4 additions & 13 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-2020 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.
@@ -39,20 +39,11 @@ public class CorsRegistry {
3939

4040
/**
4141
* Enable cross-origin request handling for the specified path pattern.
42-
*
4342
* <p>Exact path mapping URIs (such as {@code "/admin"}) are supported as
4443
* well as Ant-style path patterns (such as {@code "/admin/**"}).
45-
* <p>By default, all origins, all headers, credentials and {@code GET},
46-
* {@code HEAD}, and {@code POST} methods are allowed, and the max age
47-
* is set to 30 minutes.
48-
*
49-
* <p>The following defaults are applied to the {@link CorsRegistration}:
50-
* <ul>
51-
* <li>Allow all origins.</li>
52-
* <li>Allow "simple" methods {@code GET}, {@code HEAD} and {@code POST}.</li>
53-
* <li>Allow all headers.</li>
54-
* <li>Set max age to 1800 seconds (30 minutes).</li>
55-
* </ul>
44+
* <p>By default, the {@code CorsConfiguration} for this mapping is
45+
* initialized with default values as described in
46+
* {@link CorsConfiguration#applyPermitDefaultValues()}.
5647
*/
5748
public CorsRegistration addMapping(String pathPattern) {
5849
CorsRegistration registration = new CorsRegistration(pathPattern);

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 10 additions & 11 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-2020 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.
@@ -151,7 +151,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
151151

152152
private List<HttpMessageConverter<?>> messageConverters;
153153

154-
private List<Object> requestResponseBodyAdvice = new ArrayList<>();
154+
private final List<Object> requestResponseBodyAdvice = new ArrayList<>();
155155

156156
@Nullable
157157
private WebBindingInitializer webBindingInitializer;
@@ -180,7 +180,6 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter
180180
@Nullable
181181
private ConfigurableBeanFactory beanFactory;
182182

183-
184183
private final Map<Class<?>, SessionAttributesHandler> sessionAttributesHandlerCache = new ConcurrentHashMap<>(64);
185184

186185
private final Map<Class<?>, Set<Method>> initBinderCache = new ConcurrentHashMap<>(64);
@@ -412,7 +411,7 @@ public void setTaskExecutor(AsyncTaskExecutor taskExecutor) {
412411
* processing thread has exited and ends when the request is dispatched again
413412
* for further processing of the concurrently produced result.
414413
* <p>If this value is not set, the default timeout of the underlying
415-
* implementation is used, e.g. 10 seconds on Tomcat with Servlet 3.
414+
* implementation is used.
416415
* @param timeout the timeout value in milliseconds
417416
*/
418417
public void setAsyncRequestTimeout(long timeout) {
@@ -639,7 +638,7 @@ private void initControllerAdviceCache() {
639638
* and custom resolvers provided via {@link #setCustomArgumentResolvers}.
640639
*/
641640
private List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
642-
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
641+
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(30);
643642

644643
// Annotation-based argument resolution
645644
resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false));
@@ -686,7 +685,7 @@ private List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
686685
* methods including built-in and custom resolvers.
687686
*/
688687
private List<HandlerMethodArgumentResolver> getDefaultInitBinderArgumentResolvers() {
689-
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>();
688+
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(20);
690689

691690
// Annotation-based argument resolution
692691
resolvers.add(new RequestParamMethodArgumentResolver(getBeanFactory(), false));
@@ -719,7 +718,7 @@ private List<HandlerMethodArgumentResolver> getDefaultInitBinderArgumentResolver
719718
* custom handlers provided via {@link #setReturnValueHandlers}.
720719
*/
721720
private List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers() {
722-
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>();
721+
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(20);
723722

724723
// Single-purpose return value types
725724
handlers.add(new ModelAndViewMethodReturnValueHandler());
@@ -834,7 +833,7 @@ private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handl
834833
synchronized (this.sessionAttributesHandlerCache) {
835834
sessionAttrHandler = this.sessionAttributesHandlerCache.get(handlerType);
836835
if (sessionAttrHandler == null) {
837-
sessionAttrHandler = new SessionAttributesHandler(handlerType, sessionAttributeStore);
836+
sessionAttrHandler = new SessionAttributesHandler(handlerType, this.sessionAttributeStore);
838837
this.sessionAttributesHandlerCache.put(handlerType, sessionAttrHandler);
839838
}
840839
}
@@ -957,9 +956,9 @@ private WebDataBinderFactory getDataBinderFactory(HandlerMethod handlerMethod) t
957956
}
958957
List<InvocableHandlerMethod> initBinderMethods = new ArrayList<>();
959958
// Global methods first
960-
this.initBinderAdviceCache.forEach((clazz, methodSet) -> {
961-
if (clazz.isApplicableToBeanType(handlerType)) {
962-
Object bean = clazz.resolveBean();
959+
this.initBinderAdviceCache.forEach((controllerAdviceBean, methodSet) -> {
960+
if (controllerAdviceBean.isApplicableToBeanType(handlerType)) {
961+
Object bean = controllerAdviceBean.resolveBean();
963962
for (Method method : methodSet) {
964963
initBinderMethods.add(createInitBinderMethod(bean, method));
965964
}

0 commit comments

Comments
 (0)