Skip to content

Commit cc1f0e1

Browse files
committed
Polishing
1 parent 17a47b3 commit cc1f0e1

File tree

7 files changed

+62
-57
lines changed

7 files changed

+62
-57
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@
9090
* operating on pre-resolved bean definition metadata objects.
9191
*
9292
* <p>Note that readers for specific bean definition formats are typically
93-
* implemented separately rather than as bean factory subclasses:
94-
* see for example {@link PropertiesBeanDefinitionReader} and
93+
* implemented separately rather than as bean factory subclasses: see for example
9594
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
9695
*
9796
* <p>For an alternative implementation of the
@@ -179,7 +178,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
179178
private volatile String[] frozenBeanDefinitionNames;
180179

181180
/** Whether bean definition metadata may be cached for all beans */
182-
private volatile boolean configurationFrozen = false;
181+
private volatile boolean configurationFrozen;
183182

184183

185184
/**

spring-context/src/main/java/org/springframework/cache/support/AbstractValueAdaptingCache.java

Lines changed: 2 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.
@@ -53,8 +53,7 @@ public final boolean isAllowNullValues() {
5353

5454
@Override
5555
public ValueWrapper get(Object key) {
56-
Object value = lookup(key);
57-
return toValueWrapper(value);
56+
return toValueWrapper(lookup(key));
5857
}
5958

6059
@Override
@@ -113,5 +112,4 @@ protected Cache.ValueWrapper toValueWrapper(Object storeValue) {
113112
return (storeValue != null ? new SimpleValueWrapper(fromStoreValue(storeValue)) : null);
114113
}
115114

116-
117115
}

spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 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,16 +151,15 @@ public Object invoke(MethodInvocation mi) throws Throwable {
151151

152152
/**
153153
* Detect all PersistenceExceptionTranslators in the given BeanFactory.
154-
* @param beanFactory the ListableBeanFactory to obtaining all
155-
* PersistenceExceptionTranslators from
154+
* @param bf the ListableBeanFactory to obtain PersistenceExceptionTranslators from
156155
* @return a chained PersistenceExceptionTranslator, combining all
157-
* PersistenceExceptionTranslators found in the factory
156+
* PersistenceExceptionTranslators found in the given bean factory
158157
* @see ChainedPersistenceExceptionTranslator
159158
*/
160-
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
159+
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory bf) {
161160
// Find all translators, being careful not to activate FactoryBeans.
162161
Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
163-
beanFactory, PersistenceExceptionTranslator.class, false, false);
162+
bf, PersistenceExceptionTranslator.class, false, false);
164163
ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
165164
for (PersistenceExceptionTranslator pet : pets.values()) {
166165
cpet.addDelegate(pet);

spring-web/src/main/java/org/springframework/http/MediaType.java

Lines changed: 5 additions & 6 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.
@@ -82,7 +82,6 @@ public class MediaType extends MimeType implements Serializable {
8282

8383
/**
8484
* Public constant media type for {@code application/json}.
85-
* @see #APPLICATION_JSON_UTF8
8685
*/
8786
public final static MediaType APPLICATION_JSON;
8887

@@ -334,7 +333,7 @@ public MediaType(MediaType other, Charset charset) {
334333

335334
/**
336335
* Copy-constructor that copies the type and subtype of the given {@code MediaType},
337-
* and allows for different parameter.
336+
* and allows for different parameters.
338337
* @param other the other media type
339338
* @param parameters the parameters, may be {@code null}
340339
* @throws IllegalArgumentException if any of the parameters contain illegal characters
@@ -381,7 +380,7 @@ public double getQualityValue() {
381380
* <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html},
382381
* and {@code application/*+xml} includes {@code application/soap+xml}, etc.
383382
* This method is <b>not</b> symmetric.
384-
* <p>Simply calls {@link #includes(MimeType)} but declared with a
383+
* <p>Simply calls {@link MimeType#includes(MimeType)} but declared with a
385384
* {@code MediaType} parameter for binary backwards compatibility.
386385
* @param other the reference media type with which to compare
387386
* @return {@code true} if this media type includes the given media type;
@@ -396,7 +395,7 @@ public boolean includes(MediaType other) {
396395
* <p>For instance, {@code text/*} is compatible with {@code text/plain},
397396
* {@code text/html}, and vice versa. In effect, this method is similar to
398397
* {@link #includes}, except that it <b>is</b> symmetric.
399-
* <p>Simply calls {@link #isCompatibleWith(MimeType)} but declared with a
398+
* <p>Simply calls {@link MimeType#isCompatibleWith(MimeType)} but declared with a
400399
* {@code MediaType} parameter for binary backwards compatibility.
401400
* @param other the reference media type with which to compare
402401
* @return {@code true} if this media type is compatible with the given media type;
@@ -470,7 +469,7 @@ public static MediaType parseMediaType(String mediaType) {
470469
}
471470

472471
/**
473-
* Parse the given comma-separated string into a list of {@code MediaType} objects.
472+
* Parse the comma-separated string into a list of {@code MediaType} objects.
474473
* <p>This method can be used to parse an Accept or Content-Type header.
475474
* @param mediaTypes the string to parse
476475
* @return the list of media types

spring-web/src/main/java/org/springframework/web/bind/support/WebRequestDataBinder.java

Lines changed: 6 additions & 6 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.
@@ -106,20 +106,20 @@ public WebRequestDataBinder(Object target, String objectName) {
106106
* <p>The type of the target property for a multipart file can be Part, MultipartFile,
107107
* byte[], or String. The latter two receive the contents of the uploaded file;
108108
* all metadata like original file name, content type, etc are lost in those cases.
109-
* @param request request with parameters to bind (can be multipart)
109+
* @param request the request with parameters to bind (can be multipart)
110110
* @see org.springframework.web.multipart.MultipartRequest
111111
* @see org.springframework.web.multipart.MultipartFile
112112
* @see javax.servlet.http.Part
113113
* @see #bind(org.springframework.beans.PropertyValues)
114114
*/
115115
public void bind(WebRequest request) {
116116
MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap());
117-
if (isMultipartRequest(request) && request instanceof NativeWebRequest) {
117+
if (request instanceof NativeWebRequest) {
118118
MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class);
119119
if (multipartRequest != null) {
120120
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
121121
}
122-
else if (servlet3Parts) {
122+
else if (servlet3Parts && isMultipartRequest(request)) {
123123
HttpServletRequest serlvetRequest = ((NativeWebRequest) request).getNativeRequest(HttpServletRequest.class);
124124
new Servlet3MultipartHelper(isBindEmptyMultipartFiles()).bindParts(serlvetRequest, mpvs);
125125
}
@@ -129,11 +129,11 @@ else if (servlet3Parts) {
129129

130130
/**
131131
* Check if the request is a multipart request (by checking its Content-Type header).
132-
* @param request request with parameters to bind
132+
* @param request the request with parameters to bind
133133
*/
134134
private boolean isMultipartRequest(WebRequest request) {
135135
String contentType = request.getHeader("Content-Type");
136-
return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
136+
return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
137137
}
138138

139139
/**

spring-webmvc/src/main/java/org/springframework/web/servlet/HandlerExecutionChain.java

Lines changed: 14 additions & 5 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.
@@ -85,10 +85,16 @@ public Object getHandler() {
8585
return this.handler;
8686
}
8787

88+
/**
89+
* Add the given interceptor to the end of this chain.
90+
*/
8891
public void addInterceptor(HandlerInterceptor interceptor) {
8992
initInterceptorList().add(interceptor);
9093
}
9194

95+
/**
96+
* Add the given interceptors to the end of this chain.
97+
*/
9298
public void addInterceptors(HandlerInterceptor... interceptors) {
9399
if (!ObjectUtils.isEmpty(interceptors)) {
94100
CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList());
@@ -182,13 +188,16 @@ void applyAfterConcurrentHandlingStarted(HttpServletRequest request, HttpServlet
182188
HandlerInterceptor[] interceptors = getInterceptors();
183189
if (!ObjectUtils.isEmpty(interceptors)) {
184190
for (int i = interceptors.length - 1; i >= 0; i--) {
185-
if (interceptors[i] instanceof AsyncHandlerInterceptor) {
191+
HandlerInterceptor interceptor = interceptors[i];
192+
if (interceptor instanceof AsyncHandlerInterceptor) {
186193
try {
187-
AsyncHandlerInterceptor asyncInterceptor = (AsyncHandlerInterceptor) interceptors[i];
194+
AsyncHandlerInterceptor asyncInterceptor = (AsyncHandlerInterceptor) interceptor;
188195
asyncInterceptor.afterConcurrentHandlingStarted(request, response, this.handler);
189196
}
190197
catch (Throwable ex) {
191-
logger.error("Interceptor [" + interceptors[i] + "] failed in afterConcurrentHandlingStarted", ex);
198+
if (logger.isErrorEnabled()) {
199+
logger.error("Interceptor [" + interceptor + "] failed in afterConcurrentHandlingStarted", ex);
200+
}
192201
}
193202
}
194203
}
@@ -197,7 +206,7 @@ void applyAfterConcurrentHandlingStarted(HttpServletRequest request, HttpServlet
197206

198207

199208
/**
200-
* Delegates to the handler's {@code toString()}.
209+
* Delegates to the handler's {@code toString()} implementation.
201210
*/
202211
@Override
203212
public String toString() {

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java

Lines changed: 28 additions & 27 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.
@@ -187,17 +187,16 @@ public void setInterceptors(Object... interceptors) {
187187
}
188188

189189
/**
190-
* Set "global" CORS configuration based on URL patterns. By default the first
191-
* matching URL pattern is combined with the CORS configuration for the
192-
* handler, if any.
190+
* Set the "global" CORS configurations based on URL patterns. By default the first
191+
* matching URL pattern is combined with the CORS configuration for the handler, if any.
193192
* @since 4.2
194193
*/
195194
public void setCorsConfigurations(Map<String, CorsConfiguration> corsConfigurations) {
196195
this.globalCorsConfigSource.setCorsConfigurations(corsConfigurations);
197196
}
198197

199198
/**
200-
* Get the "global" CORS configuration.
199+
* Get the "global" CORS configurations.
201200
*/
202201
public Map<String, CorsConfiguration> getCorsConfigurations() {
203202
return this.globalCorsConfigSource.getCorsConfigurations();
@@ -261,21 +260,22 @@ protected void extendInterceptors(List<Object> interceptors) {
261260
}
262261

263262
/**
264-
* Detect beans of type {@link MappedInterceptor} and add them to the list of mapped interceptors.
265-
* <p>This is called in addition to any {@link MappedInterceptor}s that may have been provided
266-
* via {@link #setInterceptors}, by default adding all beans of type {@link MappedInterceptor}
267-
* from the current context and its ancestors. Subclasses can override and refine this policy.
268-
* @param mappedInterceptors an empty list to add {@link MappedInterceptor} instances to
263+
* Detect beans of type {@link MappedInterceptor} and add them to the list
264+
* of mapped interceptors.
265+
* <p>This is called in addition to any {@link MappedInterceptor}s that may
266+
* have been provided via {@link #setInterceptors}, by default adding all
267+
* beans of type {@link MappedInterceptor} from the current context and its
268+
* ancestors. Subclasses can override and refine this policy.
269+
* @param mappedInterceptors an empty list to add to
269270
*/
270271
protected void detectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors) {
271-
mappedInterceptors.addAll(
272-
BeanFactoryUtils.beansOfTypeIncludingAncestors(
273-
getApplicationContext(), MappedInterceptor.class, true, false).values());
272+
mappedInterceptors.addAll(BeanFactoryUtils.beansOfTypeIncludingAncestors(
273+
getApplicationContext(), MappedInterceptor.class, true, false).values());
274274
}
275275

276276
/**
277-
* Initialize the specified interceptors, checking for {@link MappedInterceptor}s and
278-
* adapting {@link HandlerInterceptor}s and {@link WebRequestInterceptor}s if necessary.
277+
* Initialize the specified interceptors adapting
278+
* {@link WebRequestInterceptor}s to {@link HandlerInterceptor}.
279279
* @see #setInterceptors
280280
* @see #adaptInterceptor
281281
*/
@@ -292,13 +292,13 @@ protected void initInterceptors() {
292292
}
293293

294294
/**
295-
* Adapt the given interceptor object to the {@link HandlerInterceptor} interface.
296-
* <p>By default, the supported interceptor types are {@link HandlerInterceptor}
297-
* and {@link WebRequestInterceptor}. Each given {@link WebRequestInterceptor}
298-
* will be wrapped in a {@link WebRequestHandlerInterceptorAdapter}.
299-
* Can be overridden in subclasses.
300-
* @param interceptor the specified interceptor object
301-
* @return the interceptor wrapped as HandlerInterceptor
295+
* Adapt the given interceptor object to {@link HandlerInterceptor}.
296+
* <p>By default, the supported interceptor types are
297+
* {@link HandlerInterceptor} and {@link WebRequestInterceptor}. Each given
298+
* {@link WebRequestInterceptor} is wrapped with
299+
* {@link WebRequestHandlerInterceptorAdapter}.
300+
* @param interceptor the interceptor
301+
* @return the interceptor downcast or adapted to HandlerInterceptor
302302
* @see org.springframework.web.servlet.HandlerInterceptor
303303
* @see org.springframework.web.context.request.WebRequestInterceptor
304304
* @see WebRequestHandlerInterceptorAdapter
@@ -317,7 +317,8 @@ else if (interceptor instanceof WebRequestInterceptor) {
317317

318318
/**
319319
* Return the adapted interceptors as {@link HandlerInterceptor} array.
320-
* @return the array of {@link HandlerInterceptor}s, or {@code null} if none
320+
* @return the array of {@link HandlerInterceptor HandlerInterceptor}s,
321+
* or {@code null} if none
321322
*/
322323
protected final HandlerInterceptor[] getAdaptedInterceptors() {
323324
int count = this.adaptedInterceptors.size();
@@ -394,8 +395,8 @@ public final HandlerExecutionChain getHandler(HttpServletRequest request) throws
394395
* Build a {@link HandlerExecutionChain} for the given handler, including
395396
* applicable interceptors.
396397
* <p>The default implementation builds a standard {@link HandlerExecutionChain}
397-
* with the given handler, the handler mapping's common interceptors, and any
398-
* {@link MappedInterceptor}s matching to the current request URL. Interceptors
398+
* with the given handler, the common interceptors of the handler mapping, and any
399+
* {@link MappedInterceptor MappedInterceptors} matching to the current request URL. Interceptors
399400
* are added in the order they were registered. Subclasses may override this
400401
* in order to extend/rearrange the list of interceptors.
401402
* <p><b>NOTE:</b> The passed-in handler object may be a raw handler or a
@@ -464,12 +465,12 @@ protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest
464465

465466
if (CorsUtils.isPreFlightRequest(request)) {
466467
HandlerInterceptor[] interceptors = chain.getInterceptors();
467-
chain = new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
468+
return new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
468469
}
469470
else {
470471
chain.addInterceptor(new CorsInterceptor(config));
472+
return chain;
471473
}
472-
return chain;
473474
}
474475

475476

0 commit comments

Comments
 (0)