diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java index 683745db15a068bde8673cccad871319a25508b0..4b7befd016746f2e971608028351e11f78d77e2e 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -186,7 +186,7 @@ class ConfigurationClassBeanDefinitionReader { // Consider name and any aliases AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.class); List names = new ArrayList<>(Arrays.asList(bean.getStringArray("name"))); - String beanName = (names.size() > 0 ? names.remove(0) : methodName); + String beanName = (!names.isEmpty() ? names.remove(0) : methodName); // Register aliases even when overridden for (String alias : names) { @@ -336,7 +336,7 @@ class ConfigurationClassBeanDefinitionReader { } readerInstanceCache.put(readerClass, reader); } - catch (Exception ex) { + catch (Throwable ex) { throw new IllegalStateException( "Could not instantiate BeanDefinitionReader class [" + readerClass.getName() + "]"); } diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java index 5c8752da4e86d834fe66fac5a79b9bba3cbfb1eb..2c61a9da3e99a0a32970e329db4de955c16f0fff 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -102,7 +102,7 @@ public class ReactiveAdapter { /** * Adapt the given instance to a Reactive Streams Publisher. * @param source the source object to adapt from - * @return the Publisher repesenting the adaptation + * @return the Publisher representing the adaptation */ @SuppressWarnings("unchecked") public Publisher toPublisher(Object source) { diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java index 7fe7a05bb072d1b4009bf4efe6fd4a648f335192..7954c8c8aa5884f433d3ba739198fc979b040787 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -30,10 +30,7 @@ import rx.RxReactiveStreams; import org.springframework.util.ClassUtils; -import static org.springframework.core.ReactiveTypeDescriptor.multiValue; -import static org.springframework.core.ReactiveTypeDescriptor.noValue; -import static org.springframework.core.ReactiveTypeDescriptor.singleOptionalValue; -import static org.springframework.core.ReactiveTypeDescriptor.singleRequiredValue; +import static org.springframework.core.ReactiveTypeDescriptor.*; /** * A registry of adapters to adapt a Reactive Streams {@link Publisher} to/from @@ -69,15 +66,12 @@ public class ReactiveAdapterRegistry { * Create a registry and auto-register default adapters. */ public ReactiveAdapterRegistry() { - if (reactorPresent) { new ReactorRegistrar().registerAdapters(this); } - if (rxJava1Present && rxJava1Adapter) { new RxJava1Registrar().registerAdapters(this); } - if (rxJava2Present) { new RxJava2Registrar().registerAdapters(this); } @@ -111,15 +105,16 @@ public class ReactiveAdapterRegistry { * Get the adapter for the given reactive type. Or if a "source" object is * provided, its actual type is used instead. * @param reactiveType the reactive type - * @param source an instance of the reactive type (i.e. to adapt from) + * (may be {@code null} if a concrete source object is given) + * @param source an instance of the reactive type + * (i.e. to adapt from; may be {@code null} if the reactive type is specified) */ public ReactiveAdapter getAdapter(Class reactiveType, Object source) { - - source = (source instanceof Optional ? ((Optional) source).orElse(null) : source); - Class clazz = (source != null ? source.getClass() : reactiveType); + Object sourceToUse = (source instanceof Optional ? ((Optional) source).orElse(null) : source); + Class clazz = (sourceToUse != null ? sourceToUse.getClass() : reactiveType); return this.adapters.stream() - .filter(adapter -> adapter.getReactiveType().equals(clazz)) + .filter(adapter -> adapter.getReactiveType() == clazz) .findFirst() .orElseGet(() -> this.adapters.stream() @@ -132,7 +127,6 @@ public class ReactiveAdapterRegistry { private static class ReactorRegistrar { void registerAdapters(ReactiveAdapterRegistry registry) { - // Flux and Mono ahead of Publisher... registry.registerReactiveType( @@ -161,6 +155,7 @@ public class ReactiveAdapterRegistry { } } + private static class RxJava1Registrar { void registerAdapters(ReactiveAdapterRegistry registry) { @@ -182,6 +177,7 @@ public class ReactiveAdapterRegistry { } } + private static class RxJava2Registrar { void registerAdapters(ReactiveAdapterRegistry registry) { @@ -213,6 +209,7 @@ public class ReactiveAdapterRegistry { } } + /** * Extension of ReactiveAdapter that wraps adapted (raw) Publisher's as * {@link Flux} or {@link Mono} depending on the underlying reactive type's diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java index 55e747b9cdcf1be04c87abee4a64cc1bd40655ff..a10b05cfd1106decaa5c83daaf44ec50f7948158 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2017 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. @@ -21,16 +21,23 @@ package org.springframework.jdbc.core.metadata; * * @author Thomas Risberg * @since 2.5 + * @see GenericCallMetaDataProvider */ public class CallParameterMetaData { + private String parameterName; + private int parameterType; + private int sqlType; + private String typeName; + private boolean nullable; + /** - * Constructor taking all the properties + * Constructor taking all the properties. */ public CallParameterMetaData(String columnName, int columnType, int sqlType, String typeName, boolean nullable) { this.parameterName = columnName; @@ -45,34 +52,35 @@ public class CallParameterMetaData { * Get the parameter name. */ public String getParameterName() { - return parameterName; + return this.parameterName; } /** * Get the parameter type. */ public int getParameterType() { - return parameterType; + return this.parameterType; } /** * Get the parameter SQL type. */ public int getSqlType() { - return sqlType; + return this.sqlType; } /** * Get the parameter type name. */ public String getTypeName() { - return typeName; + return this.typeName; } /** * Get whether the parameter is nullable. */ public boolean isNullable() { - return nullable; + return this.nullable; } + } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableParameterMetaData.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableParameterMetaData.java index 4488063b70f18018f689db30dfbfc4432a8910dd..f63f29f470476c71277fc0fea7ee8584f0a04c4a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableParameterMetaData.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableParameterMetaData.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2017 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. @@ -21,6 +21,7 @@ package org.springframework.jdbc.core.metadata; * * @author Thomas Risberg * @since 2.5 + * @see GenericTableMetaDataProvider */ public class TableParameterMetaData { diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java index 81b832970309f36c9f84966d5c37cfdf5e74a82f..43e98f3c4235fdde69709705c0ad0dd70eada756 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -426,7 +426,8 @@ public abstract class EntityManagerFactoryUtils { /** * Callback for resource cleanup at the end of a non-JPA transaction - * (e.g. when participating in a JtaTransactionManager transaction). + * (e.g. when participating in a JtaTransactionManager transaction), + * fully synchronized with the ongoing transaction. * @see org.springframework.transaction.jta.JtaTransactionManager */ private static class TransactionalEntityManagerSynchronization @@ -441,6 +442,7 @@ public abstract class EntityManagerFactoryUtils { public TransactionalEntityManagerSynchronization( EntityManagerHolder emHolder, EntityManagerFactory emf, Object txData, boolean newEm) { + super(emHolder, emf); this.transactionData = txData; this.jpaDialect = (emf instanceof EntityManagerFactoryInfo ? @@ -488,7 +490,9 @@ public abstract class EntityManagerFactoryUtils { } @Override - protected void cleanupResource(EntityManagerHolder resourceHolder, EntityManagerFactory resourceKey, boolean committed) { + protected void cleanupResource( + EntityManagerHolder resourceHolder, EntityManagerFactory resourceKey, boolean committed) { + if (!committed) { // Clear all pending inserts/updates/deletes in the EntityManager. // Necessary for pre-bound EntityManagers, to avoid inconsistent state. diff --git a/spring-test/src/test/java/org/springframework/test/context/testng/TrackingTestNGTestListener.java b/spring-test/src/test/java/org/springframework/test/context/testng/TrackingTestNGTestListener.java index a47edcb55251bb8ae78d0761f5fc8c3967893578..c7030a112cf2ab2568026f1f2bf6421e4c2c3e12 100644 --- a/spring-test/src/test/java/org/springframework/test/context/testng/TrackingTestNGTestListener.java +++ b/spring-test/src/test/java/org/springframework/test/context/testng/TrackingTestNGTestListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -30,8 +30,11 @@ import org.testng.ITestResult; public class TrackingTestNGTestListener implements ITestListener { public int testStartCount = 0; + public int testSuccessCount = 0; + public int testFailureCount = 0; + public int failedConfigurationsCount = 0; @@ -66,4 +69,5 @@ public class TrackingTestNGTestListener implements ITestListener { public void onTestSuccess(ITestResult testResult) { this.testSuccessCount++; } -} \ No newline at end of file + +} diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/WebTestClientConnectorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/WebTestClientConnectorTests.java index 9fb9580773fe89cb30a01c429ac2a2c3f8553f6e..a9ddf38dcec16eb7f90098d298d32ca210795276 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/WebTestClientConnectorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/WebTestClientConnectorTests.java @@ -32,8 +32,7 @@ import org.springframework.web.reactive.function.client.ClientRequest; import org.springframework.web.reactive.function.client.ExchangeFunction; import org.springframework.web.reactive.function.client.ExchangeFunctions; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.*; /** * Unit tests for {@link WiretapConnector}. @@ -46,7 +45,6 @@ public class WebTestClientConnectorTests { @Test @SuppressWarnings("deprecation") public void captureAndClaim() throws Exception { - ClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, "/test"); ClientHttpResponse response = new MockClientHttpResponse(HttpStatus.OK); ClientHttpConnector connector = (method, uri, fn) -> fn.apply(request).then(Mono.just(response)); diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java index 3aff0c922132d8dd081f6eb3164b9bdd2069f016..aa369188fb60a1e1f351cf68f25458aa98115a60 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequestFactory.java @@ -64,13 +64,15 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, } /** - * Indicates whether this request factory should buffer the {@linkplain ClientHttpRequest#getBody() request body} - * internally. - *

Default is {@code true}. When sending large amounts of data via POST or PUT, it is recommended - * to change this property to {@code false}, so as not to run out of memory. This will result in a - * {@link ClientHttpRequest} that either streams directly to the underlying {@link HttpURLConnection} - * (if the {@link org.springframework.http.HttpHeaders#getContentLength() Content-Length} is known in advance), - * or that will use "Chunked transfer encoding" (if the {@code Content-Length} is not known in advance). + * Indicate whether this request factory should buffer the + * {@linkplain ClientHttpRequest#getBody() request body} internally. + *

Default is {@code true}. When sending large amounts of data via POST or PUT, + * it is recommended to change this property to {@code false}, so as not to run + * out of memory. This will result in a {@link ClientHttpRequest} that either + * streams directly to the underlying {@link HttpURLConnection} (if the + * {@link org.springframework.http.HttpHeaders#getContentLength() Content-Length} + * is known in advance), or that will use "Chunked transfer encoding" + * (if the {@code Content-Length} is not known in advance). * @see #setChunkSize(int) * @see HttpURLConnection#setFixedLengthStreamingMode(int) */ @@ -79,9 +81,11 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory, } /** - * Sets the number of bytes to write in each chunk when not buffering request bodies locally. - *

Note that this parameter is only used when {@link #setBufferRequestBody(boolean) bufferRequestBody} is set - * to {@code false}, and the {@link org.springframework.http.HttpHeaders#getContentLength() Content-Length} + * Set the number of bytes to write in each chunk when not buffering request + * bodies locally. + *

Note that this parameter is only used when + * {@link #setBufferRequestBody(boolean) bufferRequestBody} is set to {@code false}, + * and the {@link org.springframework.http.HttpHeaders#getContentLength() Content-Length} * is not known in advance. * @see #setBufferRequestBody(boolean) */ diff --git a/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java index 442b97185bbc4fbd9781e1d562ea610b29cee522..48756e854ad11526cc749d1da48b9d62f343ad0e 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/WebDataBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -248,11 +248,11 @@ public class WebDataBinder extends DataBinder { * Determine an empty value for the specified field. *

Default implementation returns: *

    - *
  • {@code Boolean.FALSE} for boolean fields - *
  • an empty array for array types - *
  • Collection implementations for Collection types - *
  • Map implementations for Map types - *
  • else, {@code null} is used as default + *
  • {@code Boolean.FALSE} for boolean fields + *
  • an empty array for array types + *
  • Collection implementations for Collection types + *
  • Map implementations for Map types + *
  • else, {@code null} is used as default *
* @param field the name of the field * @param fieldType the type of the field diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java index 9a41b4044e594ae1c41c0a2092bae722204235b2..ee80d2765fb751dafd106b5a9420fd207b681f72 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeDataBinder.java @@ -24,6 +24,7 @@ import java.util.TreeMap; import reactor.core.publisher.Mono; import org.springframework.beans.MutablePropertyValues; +import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.multipart.MultipartFile; @@ -82,16 +83,14 @@ public class WebExchangeDataBinder extends WebDataBinder { for (Map.Entry> entry : params.entrySet()) { String name = entry.getKey(); List values = entry.getValue(); - if (values == null || values.isEmpty()) { + if (CollectionUtils.isEmpty(values)) { // Do nothing, no values found at all. } + else if (values.size() == 1) { + result.put(name, values.get(0)); + } else { - if (values.size() > 1) { - result.put(name, values); - } - else { - result.put(name, values.get(0)); - } + result.put(name, values); } } return result; @@ -113,7 +112,7 @@ public class WebExchangeDataBinder extends WebDataBinder { /** * Extension point that subclasses can use to add extra bind values for a * request. Invoked before {@link #doBind(MutablePropertyValues)}. - * The default implementation is empty. + *

The default implementation is empty. * @param exchange the current exchange */ protected Map getExtraValuesToBind(ServerWebExchange exchange) { diff --git a/spring-web/src/main/java/org/springframework/web/client/ResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/ResponseErrorHandler.java index 39ddfe4dd14a6acc5b9e256284fa6a26b7e28432..2ad6db45892b91e9010ca2edaf741551f48dd810 100644 --- a/spring-web/src/main/java/org/springframework/web/client/ResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/ResponseErrorHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -21,7 +21,8 @@ import java.io.IOException; import org.springframework.http.client.ClientHttpResponse; /** - * Strategy interface used by the {@link RestTemplate} to determine whether a particular response has an error or not. + * Strategy interface used by the {@link RestTemplate} to determine + * whether a particular response has an error or not. * * @author Arjen Poutsma * @since 3.0 @@ -29,9 +30,9 @@ import org.springframework.http.client.ClientHttpResponse; public interface ResponseErrorHandler { /** - * Indicates whether the given response has any errors. - * Implementations will typically inspect the {@link ClientHttpResponse#getStatusCode() HttpStatus} - * of the response. + * Indicate whether the given response has any errors. + *

Implementations will typically inspect the + * {@link ClientHttpResponse#getStatusCode() HttpStatus} of the response. * @param response the response to inspect * @return {@code true} if the response has an error; {@code false} otherwise * @throws IOException in case of I/O errors @@ -39,10 +40,12 @@ public interface ResponseErrorHandler { boolean hasError(ClientHttpResponse response) throws IOException; /** - * Handles the error in the given response. - * This method is only called when {@link #hasError(ClientHttpResponse)} has returned {@code true}. + * Handle the error in the given response. + *

This method is only called when {@link #hasError(ClientHttpResponse)} + * has returned {@code true}. * @param response the response with the error * @throws IOException in case of I/O errors */ void handleError(ClientHttpResponse response) throws IOException; + } diff --git a/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityDecoder.java b/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityDecoder.java index 75fac9a1d612ba7f0c61315c177336402157b38c..3fffd7f07ba49b8709147a3de7ea3c03632cd2a6 100644 --- a/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityDecoder.java +++ b/spring-web/src/main/java/org/springframework/web/util/HtmlCharacterEntityDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2017 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. @@ -45,90 +45,88 @@ class HtmlCharacterEntityDecoder { public HtmlCharacterEntityDecoder(HtmlCharacterEntityReferences characterEntityReferences, String original) { this.characterEntityReferences = characterEntityReferences; this.originalMessage = original; - this.decodedMessage = new StringBuilder(originalMessage.length()); + this.decodedMessage = new StringBuilder(original.length()); } + public String decode() { - while (currentPosition < originalMessage.length()) { - findNextPotentialReference(currentPosition); + while (this.currentPosition < this.originalMessage.length()) { + findNextPotentialReference(this.currentPosition); copyCharactersTillPotentialReference(); processPossibleReference(); } - return decodedMessage.toString(); + return this.decodedMessage.toString(); } private void findNextPotentialReference(int startPosition) { - nextPotentialReferencePosition = Math.max(startPosition, nextSemicolonPosition - MAX_REFERENCE_SIZE); + this.nextPotentialReferencePosition = Math.max(startPosition, this.nextSemicolonPosition - MAX_REFERENCE_SIZE); do { - nextPotentialReferencePosition = - originalMessage.indexOf('&', nextPotentialReferencePosition); + this.nextPotentialReferencePosition = + this.originalMessage.indexOf('&', this.nextPotentialReferencePosition); - if (nextSemicolonPosition != -1 && - nextSemicolonPosition < nextPotentialReferencePosition) - nextSemicolonPosition = originalMessage.indexOf(';', nextPotentialReferencePosition + 1); + if (this.nextSemicolonPosition != -1 && + this.nextSemicolonPosition < this.nextPotentialReferencePosition) + this.nextSemicolonPosition = this.originalMessage.indexOf(';', this.nextPotentialReferencePosition + 1); - boolean isPotentialReference = - nextPotentialReferencePosition != -1 - && nextSemicolonPosition != -1 - && nextPotentialReferencePosition - nextSemicolonPosition < MAX_REFERENCE_SIZE; + boolean isPotentialReference = (this.nextPotentialReferencePosition != -1 && + this.nextSemicolonPosition != -1 && + this.nextPotentialReferencePosition - this.nextSemicolonPosition < MAX_REFERENCE_SIZE); if (isPotentialReference) { break; } - if (nextPotentialReferencePosition == -1) { + if (this.nextPotentialReferencePosition == -1) { break; } - if (nextSemicolonPosition == -1) { - nextPotentialReferencePosition = -1; + if (this.nextSemicolonPosition == -1) { + this.nextPotentialReferencePosition = -1; break; } - nextPotentialReferencePosition = nextPotentialReferencePosition + 1; + this.nextPotentialReferencePosition = this.nextPotentialReferencePosition + 1; } - while (nextPotentialReferencePosition != -1); + while (this.nextPotentialReferencePosition != -1); } - private void copyCharactersTillPotentialReference() { - if (nextPotentialReferencePosition != currentPosition) { - int skipUntilIndex = nextPotentialReferencePosition != -1 ? - nextPotentialReferencePosition : originalMessage.length(); - if (skipUntilIndex - currentPosition > 3) { - decodedMessage.append(originalMessage.substring(currentPosition, skipUntilIndex)); - currentPosition = skipUntilIndex; + if (this.nextPotentialReferencePosition != this.currentPosition) { + int skipUntilIndex = (this.nextPotentialReferencePosition != -1 ? + this.nextPotentialReferencePosition : this.originalMessage.length()); + if (skipUntilIndex - this.currentPosition > 3) { + this.decodedMessage.append(this.originalMessage.substring(this.currentPosition, skipUntilIndex)); + this.currentPosition = skipUntilIndex; } else { - while (currentPosition < skipUntilIndex) - decodedMessage.append(originalMessage.charAt(currentPosition++)); + while (this.currentPosition < skipUntilIndex) + this.decodedMessage.append(this.originalMessage.charAt(this.currentPosition++)); } } } private void processPossibleReference() { - if (nextPotentialReferencePosition != -1) { - boolean isNumberedReference = originalMessage.charAt(currentPosition + 1) == '#'; + if (this.nextPotentialReferencePosition != -1) { + boolean isNumberedReference = (this.originalMessage.charAt(this.currentPosition + 1) == '#'); boolean wasProcessable = isNumberedReference ? processNumberedReference() : processNamedReference(); if (wasProcessable) { - currentPosition = nextSemicolonPosition + 1; + this.currentPosition = this.nextSemicolonPosition + 1; } else { - char currentChar = originalMessage.charAt(currentPosition); - decodedMessage.append(currentChar); - currentPosition++; + char currentChar = this.originalMessage.charAt(this.currentPosition); + this.decodedMessage.append(currentChar); + this.currentPosition++; } } } private boolean processNumberedReference() { - boolean isHexNumberedReference = - originalMessage.charAt(nextPotentialReferencePosition + 2) == 'x' || - originalMessage.charAt(nextPotentialReferencePosition + 2) == 'X'; + char referenceChar = this.originalMessage.charAt(this.nextPotentialReferencePosition + 2); + boolean isHexNumberedReference = (referenceChar == 'x' || referenceChar == 'X'); try { - int value = (!isHexNumberedReference) ? + int value = (!isHexNumberedReference ? Integer.parseInt(getReferenceSubstring(2)) : - Integer.parseInt(getReferenceSubstring(3), 16); - decodedMessage.append((char) value); + Integer.parseInt(getReferenceSubstring(3), 16)); + this.decodedMessage.append((char) value); return true; } catch (NumberFormatException ex) { @@ -138,16 +136,17 @@ class HtmlCharacterEntityDecoder { private boolean processNamedReference() { String referenceName = getReferenceSubstring(1); - char mappedCharacter = characterEntityReferences.convertToCharacter(referenceName); + char mappedCharacter = this.characterEntityReferences.convertToCharacter(referenceName); if (mappedCharacter != HtmlCharacterEntityReferences.CHAR_NULL) { - decodedMessage.append(mappedCharacter); + this.decodedMessage.append(mappedCharacter); return true; } return false; } private String getReferenceSubstring(int referenceOffset) { - return originalMessage.substring(nextPotentialReferencePosition + referenceOffset, nextSemicolonPosition); + return this.originalMessage.substring( + this.nextPotentialReferencePosition + referenceOffset, this.nextSemicolonPosition); } } diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java index 2b1c008d878faf3261df7d4d664d0419b0fcc90a..fddc74f5cae2137bf224449f4ff821e71f82e5dd 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/GsonHttpMessageConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -43,7 +43,7 @@ import static org.junit.Assert.*; */ public class GsonHttpMessageConverterTests { - private GsonHttpMessageConverter converter = new GsonHttpMessageConverter(); + private final GsonHttpMessageConverter converter = new GsonHttpMessageConverter(); @Test diff --git a/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java index 5aa2dbd88ede07fc4f9a5d228e9014e8624645af..45fd82a5ed4e5c638b21d9181f9fb38de2b43122 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -45,13 +45,13 @@ import static org.junit.Assert.assertTrue; */ public class WebExchangeDataBinderTests { - private WebExchangeDataBinder binder; - private TestBean testBean; + private WebExchangeDataBinder binder; + @Before - public void setUp() throws Exception { + public void setup() throws Exception { this.testBean = new TestBean(); this.binder = new WebExchangeDataBinder(this.testBean, "person"); this.binder.registerCustomEditor(ITestBean.class, new TestBeanPropertyEditor()); @@ -177,6 +177,7 @@ public class WebExchangeDataBinderTests { assertEquals("test", this.testBean.getSpouse().getName()); } + private String generateForm(MultiValueMap form) { StringBuilder builder = new StringBuilder(); try { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java b/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java index 13e8d3374ff6e87c7781e6f0128889c035733c54..d6e1f986fcd7ad59d2f7bd61a643587609dabd2d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/BindingContext.java @@ -41,10 +41,17 @@ public class BindingContext { private final Model model = new BindingAwareConcurrentModel(); + /** + * Create a new {@code BindingContext}. + */ public BindingContext() { this(null); } + /** + * Create a new {@code BindingContext} with the given initializer. + * @param initializer the binding initializer to apply (may be {@code null}) + */ public BindingContext(WebBindingInitializer initializer) { this.initializer = initializer; } @@ -61,11 +68,9 @@ public class BindingContext { /** * Create a {@link WebExchangeDataBinder} to apply data binding and * validation with on the target, command object. - * * @param exchange the current exchange * @param target the object to create a data binder for * @param name the name of the target object - * * @return the created data binder */ public WebExchangeDataBinder createDataBinder(ServerWebExchange exchange, Object target, String name) { @@ -86,10 +91,8 @@ public class BindingContext { /** * Create a {@link WebExchangeDataBinder} without a target object for type * conversion of request values to simple types. - * * @param exchange the current exchange * @param name the name of the target object - * * @return the created data binder */ public WebExchangeDataBinder createDataBinder(ServerWebExchange exchange, String name) { diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt index 9288040607800c5fe2b0c5ed86fdc6f2f666ef90..6e48eb4aec7f105d1027dfa89bcebc7423cbd957 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/RouterFunctionExtensions.kt @@ -49,10 +49,10 @@ import reactor.core.publisher.Mono * } * ``` * + * @author Sebastien Deleuze + * @author Yevhenii Melnyk * @since 5.0 * @see Kotlin issue about supporting ::foo for member functions - * @author Sebastien De leuze - * @author Yevhenii Melnyk */ typealias Routes = RouterDsl.() -> Unit @@ -177,7 +177,6 @@ class RouterDsl { fun pathExtension(predicate: (String) -> Boolean) = RequestPredicates.pathExtension(predicate) - fun queryParam(name: String, predicate: (String) -> Boolean, f: (ServerRequest) -> Mono) { routes += RouterFunctions.route(RequestPredicates.queryParam(name, predicate), HandlerFunction { f(it) }) } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java index ce1a1642a4bafebb0f28fffc52155394e153e000..e559e993171f439301790b0954854fd1e52a0f4d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExtendedServletRequestDataBinder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 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. @@ -54,6 +54,7 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { super(target, objectName); } + /** * Merge URI variables into the property values to use for data binding. */ @@ -65,8 +66,10 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { if (uriVars != null) { for (Entry entry : uriVars.entrySet()) { if (mpvs.contains(entry.getKey())) { - logger.warn("Skipping URI variable '" + entry.getKey() - + "' since the request contains a bind value with the same name."); + if (logger.isWarnEnabled()) { + logger.warn("Skipping URI variable '" + entry.getKey() + + "' since the request contains a bind value with the same name."); + } } else { mpvs.addPropertyValue(entry.getKey(), entry.getValue()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java index 0bae03b2894786c993f15a4859b824fa56fb237d..a59e0aa00f9eb4b59d5d05a43528ea194a9725ec 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletModelAttributeMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -48,6 +48,7 @@ import org.springframework.web.servlet.HandlerMapping; public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodProcessor { /** + * Class constructor. * @param annotationNotRequired if "true", non-simple method arguments and * return values are considered model attributes with or without a * {@code @ModelAttribute} annotation @@ -87,19 +88,19 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr * a URI variable first and then a request parameter. * @param attributeName the model attribute name * @param request the current request - * @return the request value to try to convert or {@code null} + * @return the request value to try to convert, or {@code null} if none */ protected String getRequestValueForAttribute(String attributeName, NativeWebRequest request) { Map variables = getUriTemplateVariables(request); - if (StringUtils.hasText(variables.get(attributeName))) { - return variables.get(attributeName); + String variableValue = variables.get(attributeName); + if (StringUtils.hasText(variableValue)) { + return variableValue; } - else if (StringUtils.hasText(request.getParameter(attributeName))) { - return request.getParameter(attributeName); - } - else { - return null; + String parameterValue = request.getParameter(attributeName); + if (StringUtils.hasText(parameterValue)) { + return parameterValue; } + return null; } @SuppressWarnings("unchecked") @@ -115,11 +116,12 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr *

The default implementation converts only if there a registered * {@link Converter} that can perform the conversion. * @param sourceValue the source value to create the model attribute from - * @param attributeName the name of the attribute, never {@code null} + * @param attributeName the name of the attribute (never {@code null}) * @param methodParam the method parameter * @param binderFactory for creating WebDataBinder instance * @param request the current request - * @return the created model attribute, or {@code null} + * @return the created model attribute, or {@code null} if no suitable + * conversion found * @throws Exception */ protected Object createAttributeFromRequestValue(String sourceValue, String attributeName,