Skip to content

Commit 8dd285f

Browse files
committed
Polishing
1 parent 94eee6a commit 8dd285f

File tree

13 files changed

+68
-61
lines changed

13 files changed

+68
-61
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@
9696
* operating on pre-resolved bean definition metadata objects.
9797
*
9898
* <p>Note that readers for specific bean definition formats are typically
99-
* implemented separately rather than as bean factory subclasses:
100-
* see for example {@link PropertiesBeanDefinitionReader} and
99+
* implemented separately rather than as bean factory subclasses: see for example
101100
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
102101
*
103102
* <p>For an alternative implementation of the
@@ -184,7 +183,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
184183
private volatile String[] frozenBeanDefinitionNames;
185184

186185
/** Whether bean definition metadata may be cached for all beans. */
187-
private volatile boolean configurationFrozen = false;
186+
private volatile boolean configurationFrozen;
188187

189188

190189
/**
@@ -355,12 +354,11 @@ public <T> T getBean(Class<T> requiredType, @Nullable Object... args) throws Bea
355354
}
356355

357356
@Override
358-
public <T> ObjectProvider<T> getBeanProvider(Class<T> requiredType) throws BeansException {
357+
public <T> ObjectProvider<T> getBeanProvider(Class<T> requiredType) {
359358
Assert.notNull(requiredType, "Required type must not be null");
360359
return getBeanProvider(ResolvableType.forRawClass(requiredType));
361360
}
362361

363-
@SuppressWarnings("unchecked")
364362
@Override
365363
public <T> ObjectProvider<T> getBeanProvider(ResolvableType requiredType) {
366364
return new BeanObjectProvider<T>() {
@@ -390,12 +388,14 @@ public T getIfAvailable() throws BeansException {
390388
public T getIfUnique() throws BeansException {
391389
return resolveBean(requiredType, null, true);
392390
}
391+
@SuppressWarnings("unchecked")
393392
@Override
394393
public Stream<T> stream() {
395394
return Arrays.stream(getBeanNamesForTypedStream(requiredType))
396395
.map(name -> (T) getBean(name))
397396
.filter(bean -> !(bean instanceof NullBean));
398397
}
398+
@SuppressWarnings("unchecked")
399399
@Override
400400
public Stream<T> orderedStream() {
401401
String[] beanNames = getBeanNamesForTypedStream(requiredType);

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.
@@ -55,8 +55,7 @@ public final boolean isAllowNullValues() {
5555
@Override
5656
@Nullable
5757
public ValueWrapper get(Object key) {
58-
Object value = lookup(key);
59-
return toValueWrapper(value);
58+
return toValueWrapper(lookup(key));
6059
}
6160

6261
@Override
@@ -123,5 +122,4 @@ protected Cache.ValueWrapper toValueWrapper(@Nullable Object storeValue) {
123122
return (storeValue != null ? new SimpleValueWrapper(fromStoreValue(storeValue)) : null);
124123
}
125124

126-
127125
}

spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java

Lines changed: 2 additions & 2 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.
@@ -52,7 +52,7 @@ public class FileUrlResource extends UrlResource implements WritableResource {
5252
/**
5353
* Create a new {@code FileUrlResource} based on the given URL object.
5454
* <p>Note that this does not enforce "file" as URL protocol. If a protocol
55-
* is known to be resolvable to a file,
55+
* is known to be resolvable to a file, it is acceptable for this purpose.
5656
* @param url a URL
5757
* @see ResourceUtils#isFileURL(URL)
5858
* @see #getFile()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ private static class ConcurrentLruCache<K, V> {
428428

429429
private final Function<K, V> generator;
430430

431-
private volatile int size = 0;
431+
private volatile int size;
432432

433433
public ConcurrentLruCache(int maxSize, Function<K, V> generator) {
434434
Assert.isTrue(maxSize > 0, "LRU max size should be positive");

spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketRequesterMethodArgumentResolver.java

Lines changed: 2 additions & 2 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.
@@ -60,7 +60,7 @@ public Mono<Object> resolveArgument(MethodParameter parameter, Message<?> messag
6060
return Mono.just(requester);
6161
}
6262
else if (RSocket.class.isAssignableFrom(type)) {
63-
return Mono.just(requester.rsocket());
63+
return Mono.justOrEmpty(requester.rsocket());
6464
}
6565
else {
6666
return Mono.error(new IllegalArgumentException("Unexpected parameter type: " + parameter));

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public Object invoke(MethodInvocation mi) throws Throwable {
146146
else {
147147
PersistenceExceptionTranslator translator = this.persistenceExceptionTranslator;
148148
if (translator == null) {
149-
Assert.state(this.beanFactory != null, "Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory");
149+
Assert.state(this.beanFactory != null,
150+
"Cannot use PersistenceExceptionTranslator autodetection without ListableBeanFactory");
150151
translator = detectPersistenceExceptionTranslators(this.beanFactory);
151152
this.persistenceExceptionTranslator = translator;
152153
}
@@ -157,16 +158,15 @@ public Object invoke(MethodInvocation mi) throws Throwable {
157158

158159
/**
159160
* Detect all PersistenceExceptionTranslators in the given BeanFactory.
160-
* @param beanFactory the ListableBeanFactory to obtaining all
161-
* PersistenceExceptionTranslators from
161+
* @param bf the ListableBeanFactory to obtain PersistenceExceptionTranslators from
162162
* @return a chained PersistenceExceptionTranslator, combining all
163-
* PersistenceExceptionTranslators found in the factory
163+
* PersistenceExceptionTranslators found in the given bean factory
164164
* @see ChainedPersistenceExceptionTranslator
165165
*/
166-
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory beanFactory) {
166+
protected PersistenceExceptionTranslator detectPersistenceExceptionTranslators(ListableBeanFactory bf) {
167167
// Find all translators, being careful not to activate FactoryBeans.
168168
Map<String, PersistenceExceptionTranslator> pets = BeanFactoryUtils.beansOfTypeIncludingAncestors(
169-
beanFactory, PersistenceExceptionTranslator.class, false, false);
169+
bf, PersistenceExceptionTranslator.class, false, false);
170170
ChainedPersistenceExceptionTranslator cpet = new ChainedPersistenceExceptionTranslator();
171171
for (PersistenceExceptionTranslator pet : pets.values()) {
172172
cpet.addDelegate(pet);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
* @see <a href="https://tools.ietf.org/html/rfc7231#section-3.1.1.1">
5050
* HTTP 1.1: Semantics and Content, section 3.1.1.1</a>
5151
*/
52-
@SuppressWarnings("deprecation")
5352
public class MediaType extends MimeType implements Serializable {
5453

5554
private static final long serialVersionUID = 2069937152339670231L;
@@ -647,7 +646,7 @@ else if (mediaTypes.size() == 1) {
647646
*/
648647
public static List<MediaType> asMediaTypes(List<MimeType> mimeTypes) {
649648
List<MediaType> mediaTypes = new ArrayList<>(mimeTypes.size());
650-
for(MimeType mimeType : mimeTypes) {
649+
for (MimeType mimeType : mimeTypes) {
651650
mediaTypes.add(MediaType.asMediaType(mimeType));
652651
}
653652
return mediaTypes;

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

Lines changed: 2 additions & 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.
@@ -64,7 +64,7 @@ public WebExchangeDataBinder(@Nullable Object target, String objectName) {
6464

6565
/**
6666
* Bind query params, form data, and or multipart form data to the binder target.
67-
* @param exchange the current exchange.
67+
* @param exchange the current exchange
6868
* @return a {@code Mono<Void>} when binding is complete
6969
*/
7070
public Mono<Void> bind(ServerWebExchange exchange) {

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

Lines changed: 4 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.
@@ -109,12 +109,12 @@ public WebRequestDataBinder(@Nullable Object target, String objectName) {
109109
*/
110110
public void bind(WebRequest request) {
111111
MutablePropertyValues mpvs = new MutablePropertyValues(request.getParameterMap());
112-
if (isMultipartRequest(request) && request instanceof NativeWebRequest) {
112+
if (request instanceof NativeWebRequest) {
113113
MultipartRequest multipartRequest = ((NativeWebRequest) request).getNativeRequest(MultipartRequest.class);
114114
if (multipartRequest != null) {
115115
bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
116116
}
117-
else {
117+
else if (isMultipartRequest(request)) {
118118
HttpServletRequest servletRequest = ((NativeWebRequest) request).getNativeRequest(HttpServletRequest.class);
119119
if (servletRequest != null) {
120120
bindParts(servletRequest, mpvs);
@@ -130,7 +130,7 @@ public void bind(WebRequest request) {
130130
*/
131131
private boolean isMultipartRequest(WebRequest request) {
132132
String contentType = request.getHeader("Content-Type");
133-
return StringUtils.startsWithIgnoreCase(contentType, "multipart");
133+
return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
134134
}
135135

136136
private void bindParts(HttpServletRequest request, MutablePropertyValues mpvs) {

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

Lines changed: 1 addition & 3 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.
@@ -85,7 +85,6 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
8585
}
8686

8787
@Override
88-
@SuppressWarnings("unchecked")
8988
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
9089
String attributeName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
9190
return exchange.getAttributeOrDefault(attributeName, Collections.emptyMap()).get(name);
@@ -97,7 +96,6 @@ protected void handleMissingValue(String name, MethodParameter parameter) {
9796
}
9897

9998
@Override
100-
@SuppressWarnings("unchecked")
10199
protected void handleResolvedValue(
102100
@Nullable Object arg, String name, MethodParameter parameter, Model model, ServerWebExchange exchange) {
103101

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

Lines changed: 16 additions & 4 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.
@@ -88,14 +88,23 @@ public Object getHandler() {
8888
return this.handler;
8989
}
9090

91+
/**
92+
* Add the given interceptor to the end of this chain.
93+
*/
9194
public void addInterceptor(HandlerInterceptor interceptor) {
9295
initInterceptorList().add(interceptor);
9396
}
9497

98+
/**
99+
* Add the given interceptor at the specified index of this chain.
100+
*/
95101
public void addInterceptor(int index, HandlerInterceptor interceptor) {
96102
initInterceptorList().add(index, interceptor);
97103
}
98104

105+
/**
106+
* Add the given interceptors to the end of this chain.
107+
*/
99108
public void addInterceptors(HandlerInterceptor... interceptors) {
100109
if (!ObjectUtils.isEmpty(interceptors)) {
101110
CollectionUtils.mergeArrayIntoCollection(interceptors, initInterceptorList());
@@ -192,13 +201,16 @@ void applyAfterConcurrentHandlingStarted(HttpServletRequest request, HttpServlet
192201
HandlerInterceptor[] interceptors = getInterceptors();
193202
if (!ObjectUtils.isEmpty(interceptors)) {
194203
for (int i = interceptors.length - 1; i >= 0; i--) {
195-
if (interceptors[i] instanceof AsyncHandlerInterceptor) {
204+
HandlerInterceptor interceptor = interceptors[i];
205+
if (interceptor instanceof AsyncHandlerInterceptor) {
196206
try {
197-
AsyncHandlerInterceptor asyncInterceptor = (AsyncHandlerInterceptor) interceptors[i];
207+
AsyncHandlerInterceptor asyncInterceptor = (AsyncHandlerInterceptor) interceptor;
198208
asyncInterceptor.afterConcurrentHandlingStarted(request, response, this.handler);
199209
}
200210
catch (Throwable ex) {
201-
logger.error("Interceptor [" + interceptors[i] + "] failed in afterConcurrentHandlingStarted", ex);
211+
if (logger.isErrorEnabled()) {
212+
logger.error("Interceptor [" + interceptor + "] failed in afterConcurrentHandlingStarted", ex);
213+
}
202214
}
203215
}
204216
}

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -301,22 +301,22 @@ protected void extendInterceptors(List<Object> interceptors) {
301301
}
302302

303303
/**
304-
* Detect beans of type {@link MappedInterceptor} and add them to the list of mapped interceptors.
305-
* <p>This is called in addition to any {@link MappedInterceptor MappedInterceptors} that may have been provided
306-
* via {@link #setInterceptors}, by default adding all beans of type {@link MappedInterceptor}
307-
* from the current context and its ancestors. Subclasses can override and refine this policy.
308-
* @param mappedInterceptors an empty list to add {@link MappedInterceptor} instances to
304+
* Detect beans of type {@link MappedInterceptor} and add them to the list
305+
* of mapped interceptors.
306+
* <p>This is called in addition to any {@link MappedInterceptor}s that may
307+
* have been provided via {@link #setInterceptors}, by default adding all
308+
* beans of type {@link MappedInterceptor} from the current context and its
309+
* ancestors. Subclasses can override and refine this policy.
310+
* @param mappedInterceptors an empty list to add to
309311
*/
310312
protected void detectMappedInterceptors(List<HandlerInterceptor> mappedInterceptors) {
311-
mappedInterceptors.addAll(
312-
BeanFactoryUtils.beansOfTypeIncludingAncestors(
313-
obtainApplicationContext(), MappedInterceptor.class, true, false).values());
313+
mappedInterceptors.addAll(BeanFactoryUtils.beansOfTypeIncludingAncestors(
314+
obtainApplicationContext(), MappedInterceptor.class, true, false).values());
314315
}
315316

316317
/**
317-
* Initialize the specified interceptors, checking for {@link MappedInterceptor MappedInterceptors} and
318-
* adapting {@link HandlerInterceptor}s and {@link WebRequestInterceptor HandlerInterceptor}s and
319-
* {@link WebRequestInterceptor}s if necessary.
318+
* Initialize the specified interceptors adapting
319+
* {@link WebRequestInterceptor}s to {@link HandlerInterceptor}.
320320
* @see #setInterceptors
321321
* @see #adaptInterceptor
322322
*/
@@ -333,13 +333,13 @@ protected void initInterceptors() {
333333
}
334334

335335
/**
336-
* Adapt the given interceptor object to the {@link HandlerInterceptor} interface.
337-
* <p>By default, the supported interceptor types are {@link HandlerInterceptor}
338-
* and {@link WebRequestInterceptor}. Each given {@link WebRequestInterceptor}
339-
* will be wrapped in a {@link WebRequestHandlerInterceptorAdapter}.
340-
* Can be overridden in subclasses.
341-
* @param interceptor the specified interceptor object
342-
* @return the interceptor wrapped as HandlerInterceptor
336+
* Adapt the given interceptor object to {@link HandlerInterceptor}.
337+
* <p>By default, the supported interceptor types are
338+
* {@link HandlerInterceptor} and {@link WebRequestInterceptor}. Each given
339+
* {@link WebRequestInterceptor} is wrapped with
340+
* {@link WebRequestHandlerInterceptorAdapter}.
341+
* @param interceptor the interceptor
342+
* @return the interceptor downcast or adapted to HandlerInterceptor
343343
* @see org.springframework.web.servlet.HandlerInterceptor
344344
* @see org.springframework.web.context.request.WebRequestInterceptor
345345
* @see WebRequestHandlerInterceptorAdapter
@@ -358,7 +358,8 @@ else if (interceptor instanceof WebRequestInterceptor) {
358358

359359
/**
360360
* Return the adapted interceptors as {@link HandlerInterceptor} array.
361-
* @return the array of {@link HandlerInterceptor HandlerInterceptors}, or {@code null} if none
361+
* @return the array of {@link HandlerInterceptor HandlerInterceptor}s,
362+
* or {@code null} if none
362363
*/
363364
@Nullable
364365
protected final HandlerInterceptor[] getAdaptedInterceptors() {
@@ -367,8 +368,8 @@ protected final HandlerInterceptor[] getAdaptedInterceptors() {
367368
}
368369

369370
/**
370-
* Return all configured {@link MappedInterceptor MappedInterceptors} as an array.
371-
* @return the array of {@link MappedInterceptor MappedInterceptors}, or {@code null} if none
371+
* Return all configured {@link MappedInterceptor}s as an array.
372+
* @return the array of {@link MappedInterceptor}s, or {@code null} if none
372373
*/
373374
@Nullable
374375
protected final MappedInterceptor[] getMappedInterceptors() {
@@ -447,7 +448,7 @@ else if (logger.isDebugEnabled() && !request.getDispatcherType().equals(Dispatch
447448
* Build a {@link HandlerExecutionChain} for the given handler, including
448449
* applicable interceptors.
449450
* <p>The default implementation builds a standard {@link HandlerExecutionChain}
450-
* with the given handler, the handler mapping's common interceptors, and any
451+
* with the given handler, the common interceptors of the handler mapping, and any
451452
* {@link MappedInterceptor MappedInterceptors} matching to the current request URL. Interceptors
452453
* are added in the order they were registered. Subclasses may override this
453454
* in order to extend/rearrange the list of interceptors.
@@ -529,12 +530,12 @@ protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest
529530

530531
if (CorsUtils.isPreFlightRequest(request)) {
531532
HandlerInterceptor[] interceptors = chain.getInterceptors();
532-
chain = new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
533+
return new HandlerExecutionChain(new PreFlightHandler(config), interceptors);
533534
}
534535
else {
535536
chain.addInterceptor(0, new CorsInterceptor(config));
537+
return chain;
536538
}
537-
return chain;
538539
}
539540

540541

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

Lines changed: 1 addition & 2 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.
@@ -335,7 +335,6 @@ protected String toLocaleValue(Locale locale) {
335335
* @see #setDefaultLocale
336336
* @see javax.servlet.http.HttpServletRequest#getLocale()
337337
*/
338-
@Nullable
339338
protected Locale determineDefaultLocale(HttpServletRequest request) {
340339
Locale defaultLocale = getDefaultLocale();
341340
if (defaultLocale == null) {

0 commit comments

Comments
 (0)