From 2861fc65bdc76037b5e527c75c1a91618aee5433 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 27 Sep 2019 10:17:56 +0200 Subject: [PATCH] Polishing --- .../annotation/ParserStrategyUtils.java | 5 ++- .../core/io/buffer/DataBuffer.java | 2 -- .../core/io/buffer/DataBufferUtils.java | 21 +++++------- .../springframework/util/RouteMatcher.java | 1 - .../util/SimpleRouteMatcher.java | 11 ++++-- .../jdbc/datasource/init/ScriptUtils.java | 6 ++-- .../messaging/ReactiveMessageHandler.java | 2 +- .../rsocket/annotation/ConnectMapping.java | 2 -- .../stomp/StompBrokerRelayMessageHandler.java | 1 - .../TransactionSynchronizationManager.java | 4 +-- .../http/client/MultipartBodyBuilder.java | 1 - .../reactive/JettyClientHttpConnector.java | 32 ++++++++--------- .../http/client/support/HttpAccessor.java | 3 +- .../http/codec/cbor/Jackson2CborDecoder.java | 2 ++ .../http/codec/cbor/Jackson2CborEncoder.java | 2 ++ .../converter/FormHttpMessageConverter.java | 8 ++--- .../http/server/PathContainer.java | 4 --- .../ServerWebExchangeContextFilter.java | 1 + .../handler/ExceptionHandlingWebHandler.java | 8 +++-- .../server/handler/WebHandlerDecorator.java | 9 ++++- .../springframework/web/util/UriBuilder.java | 4 +-- .../web/util/UriComponentsBuilder.java | 4 +-- .../web/util/pattern/PathPattern.java | 26 ++++++-------- .../web/reactive/function/BodyInserters.java | 5 +-- .../function/server/EntityResponse.java | 4 +-- .../function/server/RouterFunctions.java | 1 - .../handler/AbstractHandlerMapping.java | 2 +- .../handler/SimpleUrlHandlerMapping.java | 1 - .../RequestBodyMethodArgumentResolver.java | 4 +-- .../WebMvcConfigurationSupport.java | 34 ++++++++++--------- .../handler/AbstractHandlerMapping.java | 2 +- .../handler/SimpleUrlHandlerMapping.java | 1 - .../view/AbstractCachingViewResolver.java | 12 +++---- .../messaging/StompSubProtocolHandler.java | 2 +- .../SubProtocolWebSocketHandler.java | 2 +- 35 files changed, 108 insertions(+), 121 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java b/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java index 4ecae70e6a..0aa2965b74 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java @@ -52,9 +52,8 @@ abstract class ParserStrategyUtils { * @since 5.2 */ @SuppressWarnings("unchecked") - static T instantiateClass(Class clazz, Class assignableTo, - Environment environment, ResourceLoader resourceLoader, - BeanDefinitionRegistry registry) { + static T instantiateClass(Class clazz, Class assignableTo, Environment environment, + ResourceLoader resourceLoader, BeanDefinitionRegistry registry) { Assert.notNull(clazz, "Class must not be null"); Assert.isAssignable(assignableTo, clazz); diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java index ca7ad0f3ea..6f5a38bded 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBuffer.java @@ -358,7 +358,6 @@ public interface DataBuffer { /** * Return this buffer's data a String using the specified charset. Default implementation * delegates to {@code toString(readPosition(), readableByteCount(), charset)}. - * * @param charset the character set to use * @return a string representation of all this buffers data * @since 5.2 @@ -370,7 +369,6 @@ public interface DataBuffer { /** * Return a part of this buffer's data as a String using the specified charset. - * * @param index the index at which to start the string * @param length the number of bytes to use for the string * @param charset the charset to use diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java index 28d5c6eb03..197e476218 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java @@ -164,8 +164,9 @@ public abstract class DataBufferUtils { * @return a Flux of data buffers read from the given channel * @since 5.2 */ - public static Flux read(Path path, DataBufferFactory bufferFactory, int bufferSize, - OpenOption... options) { + public static Flux read( + Path path, DataBufferFactory bufferFactory, int bufferSize, OpenOption... options) { + Assert.notNull(path, "Path must not be null"); Assert.notNull(bufferFactory, "BufferFactory must not be null"); Assert.isTrue(bufferSize > 0, "'bufferSize' must be > 0"); @@ -538,8 +539,8 @@ public abstract class DataBufferUtils { } /** - * Return a {@link Matcher} for the given delimiter. The matcher can be used to find the - * delimiters in data buffers. + * Return a {@link Matcher} for the given delimiter. + * The matcher can be used to find the delimiters in data buffers. * @param delimiter the delimiter bytes to find * @return the matcher * @since 5.2 @@ -549,8 +550,8 @@ public abstract class DataBufferUtils { return new KnuthMorrisPrattMatcher(delimiter); } - /** Return a {@link Matcher} for the given delimiters. The matcher can be used to find the - * delimiters in data buffers. + /** Return a {@link Matcher} for the given delimiters. + * The matcher can be used to find the delimiters in data buffers. * @param delimiters the delimiters bytes to find * @return the matcher * @since 5.2 @@ -595,7 +596,6 @@ public abstract class DataBufferUtils { * Resets the state of this matcher. */ void reset(); - } @@ -730,7 +730,6 @@ public abstract class DataBufferUtils { private boolean isNotDisposed() { return !this.disposed.get(); } - } @@ -866,12 +865,11 @@ public abstract class DataBufferUtils { this.sink.next(dataBuffer); this.dataBuffer.set(null); } - } + /** * Implementation of {@link Matcher} that uses the Knuth-Morris-Pratt algorithm. - * * @see Knuth-Morris-Pratt string matching */ private static class KnuthMorrisPrattMatcher implements Matcher { @@ -882,7 +880,6 @@ public abstract class DataBufferUtils { private int matches = 0; - public KnuthMorrisPrattMatcher(byte[] delimiter) { this.delimiter = Arrays.copyOf(delimiter, delimiter.length); this.table = longestSuffixPrefixTable(delimiter); @@ -935,6 +932,7 @@ public abstract class DataBufferUtils { } } + /** * Implementation of {@link Matcher} that wraps several other matchers. */ @@ -946,7 +944,6 @@ public abstract class DataBufferUtils { byte[] longestDelimiter = NO_DELIMITER; - public CompositeMatcher(Matcher[] matchers) { this.matchers = matchers; } diff --git a/spring-core/src/main/java/org/springframework/util/RouteMatcher.java b/spring-core/src/main/java/org/springframework/util/RouteMatcher.java index bf03b7b146..166f9e677d 100644 --- a/spring-core/src/main/java/org/springframework/util/RouteMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/RouteMatcher.java @@ -42,7 +42,6 @@ public interface RouteMatcher { */ Route parseRoute(String routeValue); - /** * Whether the given {@code route} contains pattern syntax which requires * the {@link #match(String, Route)} method, or if it is a regular String diff --git a/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java b/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java index 3cf7e2e02a..ead414e1f3 100644 --- a/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.util; import java.util.Comparator; @@ -36,12 +37,18 @@ public class SimpleRouteMatcher implements RouteMatcher { private final PathMatcher pathMatcher; + /** + * Create a new {@code SimpleRouteMatcher} for the given + * {@link PathMatcher} delegate. + */ public SimpleRouteMatcher(PathMatcher pathMatcher) { Assert.notNull(pathMatcher, "PathMatcher is required"); this.pathMatcher = pathMatcher; } - + /** + * Return the underlying {@link PathMatcher} delegate. + */ public PathMatcher getPathMatcher() { return this.pathMatcher; } @@ -86,12 +93,10 @@ public class SimpleRouteMatcher implements RouteMatcher { private final String path; - DefaultRoute(String path) { this.path = path; } - @Override public String value() { return this.path; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java index bb24ad95d0..6ee6be6e1b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java @@ -85,7 +85,7 @@ public abstract class ScriptUtils { * Default prefixes for single-line comments within SQL scripts: {@code ["--"]}. * @since 5.2 */ - public static final String[] DEFAULT_COMMENT_PREFIXES = { DEFAULT_COMMENT_PREFIX }; + public static final String[] DEFAULT_COMMENT_PREFIXES = {DEFAULT_COMMENT_PREFIX}; /** * Default start delimiter for block comments within SQL scripts: {@code "/*"}. @@ -214,8 +214,8 @@ public abstract class ScriptUtils { Assert.hasText(script, "'script' must not be null or empty"); Assert.notNull(separator, "'separator' must not be null"); Assert.notEmpty(commentPrefixes, "'commentPrefixes' must not be null or empty"); - for (int i = 0; i < commentPrefixes.length; i++) { - Assert.hasText(commentPrefixes[i], "'commentPrefixes' must not contain null or empty elements"); + for (String commentPrefix : commentPrefixes) { + Assert.hasText(commentPrefix, "'commentPrefixes' must not contain null or empty elements"); } Assert.hasText(blockCommentStartDelimiter, "'blockCommentStartDelimiter' must not be null or empty"); Assert.hasText(blockCommentEndDelimiter, "'blockCommentEndDelimiter' must not be null or empty"); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/ReactiveMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/ReactiveMessageHandler.java index 7b9ca66872..a11c496d0d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/ReactiveMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/ReactiveMessageHandler.java @@ -31,7 +31,7 @@ public interface ReactiveMessageHandler { /** * Handle the given message. * @param message the message to be handled - * @return a completion {@link Mono} for the result of the message handling. + * @return a completion {@link Mono} for the result of the message handling */ Mono handleMessage(Message message); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java index 2c7eb7ab9f..8fb2de46c2 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/ConnectMapping.java @@ -55,12 +55,10 @@ public @interface ConnectMapping { * Mappings expressed by this annotation to match to the route from the * metadata of the initial {@link ConnectionSetupPayload} or in * subsequent metadata pushes. - * *

Depending on the configured * {@link org.springframework.util.RouteMatcher RouteMatcher}, the pattern may be * {@link org.springframework.util.AntPathMatcher AntPathMatcher} or * {@link org.springframework.web.util.pattern.PathPattern PathPattern} based. - * *

By default this is an empty array in which case it matches all * {@link ConnectionSetupPayload} and metadata pushes. */ diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java index 3cb2b87db7..b579259303 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java @@ -1053,7 +1053,6 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler private final AtomicInteger disconnect = new AtomicInteger(); - public void incrementConnectCount() { this.connect.incrementAndGet(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java index 4ac960cfdb..d6daab76de 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java @@ -125,9 +125,7 @@ public class TransactionSynchronizationManager { */ @Nullable private Object doGetResource(Object actualKey) { - Map map = this.transactionContext.getResources(); - Object value = map.get(actualKey); - return value; + return this.transactionContext.getResources().get(actualKey); } /** diff --git a/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java b/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java index d63f65f142..1d35cd34a4 100644 --- a/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java @@ -171,7 +171,6 @@ public final class MultipartBodyBuilder { * @param elementClass the type of elements contained in the publisher * @return builder that allows for further customization of part headers */ - @SuppressWarnings("unchecked") public > PartBuilder asyncPart(String name, P publisher, Class elementClass) { Assert.hasLength(name, "'name' must not be empty"); Assert.notNull(publisher, "'publisher' must not be null"); diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java index 7b1c2d3bfc..481d3c0582 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java @@ -53,21 +53,6 @@ public class JettyClientHttpConnector implements ClientHttpConnector { this(new HttpClient()); } - /** - * Constructor with an {@link JettyResourceFactory} that will manage shared resources. - * @param resourceFactory the {@link JettyResourceFactory} to use - * @param customizer the lambda used to customize the {@link HttpClient} - * @deprecated as of 5.2, in favor of {@link JettyClientHttpConnector#JettyClientHttpConnector(HttpClient, JettyResourceFactory)} - */ - @Deprecated - public JettyClientHttpConnector( - JettyResourceFactory resourceFactory, @Nullable Consumer customizer) { - this(new HttpClient(), resourceFactory); - if (customizer != null) { - customizer.accept(this.httpClient); - } - } - /** * Constructor with an initialized {@link HttpClient}. */ @@ -82,8 +67,7 @@ public class JettyClientHttpConnector implements ClientHttpConnector { * @param resourceFactory the {@link JettyResourceFactory} to use * @since 5.2 */ - public JettyClientHttpConnector(HttpClient httpClient, - @Nullable JettyResourceFactory resourceFactory) { + public JettyClientHttpConnector(HttpClient httpClient, @Nullable JettyResourceFactory resourceFactory) { Assert.notNull(httpClient, "HttpClient is required"); if (resourceFactory != null) { httpClient.setExecutor(resourceFactory.getExecutor()); @@ -93,6 +77,20 @@ public class JettyClientHttpConnector implements ClientHttpConnector { this.httpClient = httpClient; } + /** + * Constructor with an {@link JettyResourceFactory} that will manage shared resources. + * @param resourceFactory the {@link JettyResourceFactory} to use + * @param customizer the lambda used to customize the {@link HttpClient} + * @deprecated as of 5.2, in favor of {@link JettyClientHttpConnector#JettyClientHttpConnector(HttpClient, JettyResourceFactory)} + */ + @Deprecated + public JettyClientHttpConnector(JettyResourceFactory resourceFactory, @Nullable Consumer customizer) { + this(new HttpClient(), resourceFactory); + if (customizer != null) { + customizer.accept(this.httpClient); + } + } + public void setBufferFactory(DataBufferFactory bufferFactory) { this.bufferFactory = bufferFactory; diff --git a/spring-web/src/main/java/org/springframework/http/client/support/HttpAccessor.java b/spring-web/src/main/java/org/springframework/http/client/support/HttpAccessor.java index 1232865df7..e2d59b6347 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/HttpAccessor.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/HttpAccessor.java @@ -130,8 +130,7 @@ public abstract class HttpAccessor { } private void initialize(ClientHttpRequest request) { - this.clientHttpRequestInitializers.forEach( - initializer -> initializer.initialize(request)); + this.clientHttpRequestInitializers.forEach(initializer -> initializer.initialize(request)); } } diff --git a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java index 18d4f87935..35bb39f093 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java @@ -51,8 +51,10 @@ public class Jackson2CborDecoder extends AbstractJackson2Decoder { Assert.isAssignable(CBORFactory.class, mapper.getFactory().getClass()); } + @Override public Flux decode(Publisher input, ResolvableType elementType, MimeType mimeType, Map hints) { throw new UnsupportedOperationException("Does not support stream decoding yet"); } + } diff --git a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java index a72f0a02b3..424e3ec4b6 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java @@ -52,8 +52,10 @@ public class Jackson2CborEncoder extends AbstractJackson2Encoder { Assert.isAssignable(CBORFactory.class, mapper.getFactory().getClass()); } + @Override public Flux encode(Publisher inputStream, DataBufferFactory bufferFactory, ResolvableType elementType, MimeType mimeType, Map hints) { throw new UnsupportedOperationException("Does not support stream encoding yet"); } + } diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index 69d0226b8c..fa79ef77aa 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -203,22 +203,18 @@ public class FormHttpMessageConverter implements HttpMessageConverterThe supplied {@code MediaType} objects will be appended to the list * of {@linkplain #getSupportedMediaTypes() supported MediaType objects}. - * @param supportedMediaTypes a var-args list of {@code MediaType} objects - * to add + * @param supportedMediaTypes a var-args list of {@code MediaType} objects to add * @since 5.2 * @see #setSupportedMediaTypes(List) */ public void addSupportedMediaTypes(MediaType... supportedMediaTypes) { Assert.notNull(supportedMediaTypes, "'supportedMediaTypes' must not be null"); Assert.noNullElements(supportedMediaTypes, "'supportedMediaTypes' must not contain null elements"); - for (MediaType mediaType : supportedMediaTypes) { - this.supportedMediaTypes.add(mediaType); - } + Collections.addAll(this.supportedMediaTypes, supportedMediaTypes); } /** * {@inheritDoc} - * * @see #setSupportedMediaTypes(List) * @see #addSupportedMediaTypes(MediaType...) */ diff --git a/spring-web/src/main/java/org/springframework/http/server/PathContainer.java b/spring-web/src/main/java/org/springframework/http/server/PathContainer.java index 53363af422..9da528f52e 100644 --- a/spring-web/src/main/java/org/springframework/http/server/PathContainer.java +++ b/spring-web/src/main/java/org/springframework/http/server/PathContainer.java @@ -148,18 +148,15 @@ public interface PathContainer { */ public final static Options MESSAGE_ROUTE = Options.create('.', false); - private final char separator; private final boolean decodeAndParseSegments; - private Options(char separator, boolean decodeAndParseSegments) { this.separator = separator; this.decodeAndParseSegments = decodeAndParseSegments; } - public char separator() { return this.separator; } @@ -168,7 +165,6 @@ public interface PathContainer { return this.decodeAndParseSegments; } - /** * Create an {@link Options} instance with the given settings. * @param separator the separator for parsing the path into segments; diff --git a/spring-web/src/main/java/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.java b/spring-web/src/main/java/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.java index db376c7019..094a6f6529 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.web.filter.reactive; import java.util.Optional; diff --git a/spring-web/src/main/java/org/springframework/web/server/handler/ExceptionHandlingWebHandler.java b/spring-web/src/main/java/org/springframework/web/server/handler/ExceptionHandlingWebHandler.java index 0338e90caa..da53f6a3c0 100644 --- a/spring-web/src/main/java/org/springframework/web/server/handler/ExceptionHandlingWebHandler.java +++ b/spring-web/src/main/java/org/springframework/web/server/handler/ExceptionHandlingWebHandler.java @@ -38,10 +38,14 @@ import org.springframework.web.server.WebHandler; */ public class ExceptionHandlingWebHandler extends WebHandlerDecorator { - private final List exceptionHandlers; + /** + * Create an {@code ExceptionHandlingWebHandler} for the given delegate. + * @param delegate the WebHandler delegate + * @param handlers the WebExceptionHandlers to apply + */ public ExceptionHandlingWebHandler(WebHandler delegate, List handlers) { super(delegate); List handlersToUse = new ArrayList<>(); @@ -61,7 +65,6 @@ public class ExceptionHandlingWebHandler extends WebHandlerDecorator { @Override public Mono handle(ServerWebExchange exchange) { - Mono completion; try { completion = super.handle(exchange); @@ -73,7 +76,6 @@ public class ExceptionHandlingWebHandler extends WebHandlerDecorator { for (WebExceptionHandler handler : this.exceptionHandlers) { completion = completion.onErrorResume(ex -> handler.handle(exchange, ex)); } - return completion; } diff --git a/spring-web/src/main/java/org/springframework/web/server/handler/WebHandlerDecorator.java b/spring-web/src/main/java/org/springframework/web/server/handler/WebHandlerDecorator.java index 4f917c54fe..9c3374c205 100644 --- a/spring-web/src/main/java/org/springframework/web/server/handler/WebHandlerDecorator.java +++ b/spring-web/src/main/java/org/springframework/web/server/handler/WebHandlerDecorator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,12 +33,19 @@ public class WebHandlerDecorator implements WebHandler { private final WebHandler delegate; + /** + * Create a {@code WebHandlerDecorator} for the given delegate. + * @param delegate the WebHandler delegate + */ public WebHandlerDecorator(WebHandler delegate) { Assert.notNull(delegate, "'delegate' must not be null"); this.delegate = delegate; } + /** + * Return the wrapped delegate. + */ public WebHandler getDelegate() { return this.delegate; } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java index bcbb96e57b..bd65446082 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java @@ -136,7 +136,7 @@ public interface UriBuilder { * only (i.e. {@code ?foo} instead of {@code ?foo=bar}. * @param name the query parameter name * @param values the query parameter values - * @since 5.2.0 + * @since 5.2 * @see #queryParam(String, Object...) */ UriBuilder queryParam(String name, @Nullable Collection values); @@ -161,7 +161,7 @@ public interface UriBuilder { * the same parameter. If no values are given, the query parameter is removed. * @param name the query parameter name * @param values the query parameter values - * @since 5.2.0 + * @since 5.2 * @see #replaceQueryParam(String, Object...) */ UriBuilder replaceQueryParam(String name, @Nullable Collection values); diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index 99d7267d2c..12ca9b7eac 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -725,7 +725,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @param name the query parameter name * @param values the query parameter values * @return this UriComponentsBuilder - * @since 5.2.0 + * @since 5.2 * @see #queryParam(String, Object...) */ @Override @@ -773,7 +773,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { * @param values the query parameter values * @return this UriComponentsBuilder * @see #replaceQueryParam(String, Object...) - * @since 5.2.0 + * @since 5.2 */ @Override public UriComponentsBuilder replaceQueryParam(String name, @Nullable Collection values) { diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java index d706474253..85216a8cda 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPattern.java @@ -176,7 +176,6 @@ public class PathPattern implements Comparable { return this.patternString; } - /** * Whether the pattern string contains pattern syntax that would require * use of {@link #matches(PathContainer)}, or if it is a regular String that @@ -184,7 +183,7 @@ public class PathPattern implements Comparable { * @since 5.2 */ public boolean hasPatternSyntax() { - return this.score > 0 || this.patternString.indexOf('?') != -1; + return (this.score > 0 || this.patternString.indexOf('?') != -1); } /** @@ -218,9 +217,9 @@ public class PathPattern implements Comparable { @Nullable public PathMatchInfo matchAndExtract(PathContainer pathContainer) { if (this.head == null) { - return hasLength(pathContainer) && - !(this.matchOptionalTrailingSeparator && pathContainerIsJustSeparator(pathContainer)) - ? null : PathMatchInfo.EMPTY; + return (hasLength(pathContainer) && + !(this.matchOptionalTrailingSeparator && pathContainerIsJustSeparator(pathContainer)) ? + null : PathMatchInfo.EMPTY); } else if (!hasLength(pathContainer)) { if (this.head instanceof WildcardTheRestPathElement || this.head instanceof CaptureTheRestPathElement) { @@ -442,6 +441,7 @@ public class PathPattern implements Comparable { return this.patternString; } + int getScore() { return this.score; } @@ -537,30 +537,25 @@ public class PathPattern implements Comparable { pathContainer.value().charAt(0) == getSeparator(); } + /** * Holder for URI variables and path parameters (matrix variables) extracted * based on the pattern for a given matched path. */ public static class PathMatchInfo { - private static final PathMatchInfo EMPTY = - new PathMatchInfo(Collections.emptyMap(), Collections.emptyMap()); - + private static final PathMatchInfo EMPTY = new PathMatchInfo(Collections.emptyMap(), Collections.emptyMap()); private final Map uriVariables; private final Map> matrixVariables; - - PathMatchInfo(Map uriVars, - @Nullable Map> matrixVars) { - + PathMatchInfo(Map uriVars, @Nullable Map> matrixVars) { this.uriVariables = Collections.unmodifiableMap(uriVars); - this.matrixVariables = matrixVars != null ? - Collections.unmodifiableMap(matrixVars) : Collections.emptyMap(); + this.matrixVariables = (matrixVars != null ? + Collections.unmodifiableMap(matrixVars) : Collections.emptyMap()); } - /** * Return the extracted URI variables. */ @@ -717,4 +712,5 @@ public class PathPattern implements Comparable { return ""; } } + } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java index 964372da49..0d9004d099 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java @@ -154,8 +154,9 @@ public abstract class BodyInserters { * @return the inserter to write a producer * @since 5.2 */ - public static BodyInserter fromProducer(T producer, - ParameterizedTypeReference elementTypeRef) { + public static BodyInserter fromProducer( + T producer, ParameterizedTypeReference elementTypeRef) { + Assert.notNull(producer, "'producer' must not be null"); Assert.notNull(elementTypeRef, "'elementTypeRef' must not be null"); ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(producer.getClass()); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/EntityResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/EntityResponse.java index 2091231510..a659e4ee30 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/EntityResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/EntityResponse.java @@ -91,9 +91,7 @@ public interface EntityResponse extends ServerResponse { * @return the created builder * @since 5.2 */ - static Builder fromProducer(T producer, - ParameterizedTypeReference typeReference) { - + static Builder fromProducer(T producer, ParameterizedTypeReference typeReference) { return new DefaultEntityResponseBuilder<>(producer, BodyInserters.fromProducer(producer, typeReference)); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunctions.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunctions.java index 7c8d814e93..9eb309c530 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunctions.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunctions.java @@ -444,7 +444,6 @@ public abstract class RouterFunctions { /** * Adds a route to the given handler function that handles all requests that match the * given predicate. - * * @param predicate the request predicate to match * @param handlerFunction the handler function to handle all requests that match the predicate * @return this builder diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java index a323217cd8..848249f976 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/AbstractHandlerMapping.java @@ -212,7 +212,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport * @since 5.2 */ protected boolean hasCorsConfigurationSource(Object handler) { - return handler instanceof CorsConfigurationSource || this.corsConfigurationSource != null; + return (handler instanceof CorsConfigurationSource || this.corsConfigurationSource != null); } /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMapping.java index 3e6e5c0f59..430681f85b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/SimpleUrlHandlerMapping.java @@ -58,7 +58,6 @@ public class SimpleUrlHandlerMapping extends AbstractUrlHandlerMapping { /** * Create a {@code SimpleUrlHandlerMapping} with default settings. - * @since 5.2 */ public SimpleUrlHandlerMapping() { } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolver.java index 16f1049afc..c1bce52df9 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestBodyMethodArgumentResolver.java @@ -45,9 +45,7 @@ import org.springframework.web.server.ServerWebInputException; */ public class RequestBodyMethodArgumentResolver extends AbstractMessageReaderArgumentResolver { - public RequestBodyMethodArgumentResolver(List> readers, - ReactiveAdapterRegistry registry) { - + public RequestBodyMethodArgumentResolver(List> readers, ReactiveAdapterRegistry registry) { super(readers, registry); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 7401b969c5..e59868bfba 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -276,8 +276,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv @Bean public RequestMappingHandlerMapping requestMappingHandlerMapping( ContentNegotiationManager mvcContentNegotiationManager, - FormattingConversionService mvcConversionService, - ResourceUrlProvider mvcResourceUrlProvider) { + FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) { + RequestMappingHandlerMapping mapping = createRequestMappingHandlerMapping(); mapping.setOrder(0); mapping.setInterceptors(getInterceptors(mvcConversionService, mvcResourceUrlProvider)); @@ -477,8 +477,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * paths to controller bean names. */ @Bean - public BeanNameUrlHandlerMapping beanNameHandlerMapping(FormattingConversionService mvcConversionService, - ResourceUrlProvider mvcResourceUrlProvider) { + public BeanNameUrlHandlerMapping beanNameHandlerMapping( + FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) { + BeanNameUrlHandlerMapping mapping = new BeanNameUrlHandlerMapping(); mapping.setOrder(2); mapping.setInterceptors(getInterceptors(mvcConversionService, mvcResourceUrlProvider)); @@ -498,8 +499,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * @since 5.2 */ @Bean - public RouterFunctionMapping routerFunctionMapping(FormattingConversionService mvcConversionService, - ResourceUrlProvider mvcResourceUrlProvider) { + public RouterFunctionMapping routerFunctionMapping( + FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) { + RouterFunctionMapping mapping = new RouterFunctionMapping(); mapping.setOrder(3); mapping.setInterceptors(getInterceptors(mvcConversionService, mvcResourceUrlProvider)); @@ -516,10 +518,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv @Bean @Nullable public HandlerMapping resourceHandlerMapping(UrlPathHelper mvcUrlPathHelper, - PathMatcher mvcPathMatcher, - ContentNegotiationManager mvcContentNegotiationManager, - FormattingConversionService mvcConversionService, - ResourceUrlProvider mvcResourceUrlProvider) { + PathMatcher mvcPathMatcher, ContentNegotiationManager mvcContentNegotiationManager, + FormattingConversionService mvcConversionService, ResourceUrlProvider mvcResourceUrlProvider) { + Assert.state(this.applicationContext != null, "No ApplicationContext set"); Assert.state(this.servletContext != null, "No ServletContext set"); @@ -597,8 +598,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv @Bean public RequestMappingHandlerAdapter requestMappingHandlerAdapter( ContentNegotiationManager mvcContentNegotiationManager, - FormattingConversionService mvcConversionService, - Validator mvcValidator) { + FormattingConversionService mvcConversionService, Validator mvcValidator) { + RequestMappingHandlerAdapter adapter = createRequestMappingHandlerAdapter(); adapter.setContentNegotiationManager(mvcContentNegotiationManager); adapter.setMessageConverters(getMessageConverters()); @@ -649,8 +650,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * initializing all {@link WebDataBinder} instances. */ protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer( - FormattingConversionService mvcConversionService, - Validator mvcValidator) { + FormattingConversionService mvcConversionService, Validator mvcValidator) { + ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(mvcConversionService); initializer.setValidator(mvcValidator); @@ -980,6 +981,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv */ protected final void addDefaultHandlerExceptionResolvers(List exceptionResolvers, ContentNegotiationManager mvcContentNegotiationManager) { + ExceptionHandlerExceptionResolver exceptionHandlerResolver = createExceptionHandlerExceptionResolver(); exceptionHandlerResolver.setContentNegotiationManager(mvcContentNegotiationManager); exceptionHandlerResolver.setMessageConverters(getMessageConverters()); @@ -1025,8 +1027,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv */ @Bean public ViewResolver mvcViewResolver(ContentNegotiationManager mvcContentNegotiationManager) { - ViewResolverRegistry registry = new ViewResolverRegistry( - mvcContentNegotiationManager, this.applicationContext); + ViewResolverRegistry registry = + new ViewResolverRegistry(mvcContentNegotiationManager, this.applicationContext); configureViewResolvers(registry); if (registry.getViewResolvers().isEmpty() && this.applicationContext != null) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index 3d2c3da42f..42566bdaec 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -485,7 +485,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @since 5.2 */ protected boolean hasCorsConfigurationSource(Object handler) { - return handler instanceof CorsConfigurationSource || this.corsConfigurationSource != null; + return (handler instanceof CorsConfigurationSource || this.corsConfigurationSource != null); } /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMapping.java index a16c07b421..b39b46ecb6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleUrlHandlerMapping.java @@ -63,7 +63,6 @@ public class SimpleUrlHandlerMapping extends AbstractUrlHandlerMapping { /** * Create a {@code SimpleUrlHandlerMapping} with default settings. - * @since 5.2 */ public SimpleUrlHandlerMapping() { } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java index 8b61f6129c..b7f0ebfbcc 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractCachingViewResolver.java @@ -303,14 +303,14 @@ public abstract class AbstractCachingViewResolver extends WebApplicationObjectSu public interface CacheFilter { /** - * Indicates whether the given view should be cached. The name and - * locale used to resolve the view are also provided. + * Indicates whether the given view should be cached. + * The name and locale used to resolve the view are also provided. * @param view the view - * @param viewName the name used to resolve {@code view} - * @param locale the locale used to resolve {@code view} - * @return {@code true} if the view should be cached; {@code false} - * otherwise + * @param viewName the name used to resolve the {@code view} + * @param locale the locale used to resolve the {@code view} + * @return {@code true} if the view should be cached; {@code false} otherwise */ boolean filter(View view, String viewName, Locale locale); } + } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java index 39e8c97a86..f483ca0c6e 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/StompSubProtocolHandler.java @@ -652,6 +652,7 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE return MessageBuilder.createMessage(EMPTY_PAYLOAD, headerAccessor.getMessageHeaders()); } + @Override public String toString() { return "StompSubProtocolHandler" + getSupportedProtocols(); @@ -689,7 +690,6 @@ public class StompSubProtocolHandler implements SubProtocolHandler, ApplicationE private final AtomicInteger disconnect = new AtomicInteger(); - public void incrementConnectCount() { this.connect.incrementAndGet(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java index 76df91c137..91c4690b12 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java @@ -595,6 +595,7 @@ public class SubProtocolWebSocketHandler int getTransportErrorSessions(); } + private class DefaultStats implements Stats { private final AtomicInteger total = new AtomicInteger(); @@ -611,7 +612,6 @@ public class SubProtocolWebSocketHandler private final AtomicInteger transportError = new AtomicInteger(); - @Override public int getTotalSessions() { return this.total.get();