diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java index 6483bb0b4e..ab70bf9b38 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java @@ -160,7 +160,7 @@ public class EnableAsyncTests { Object bean = ctx.getBean(CustomAsyncBean.class); assertTrue(AopUtils.isAopProxy(bean)); boolean isAsyncAdvised = false; - for (Advisor advisor : ((Advised)bean).getAdvisors()) { + for (Advisor advisor : ((Advised) bean).getAdvisors()) { if (advisor instanceof AsyncAnnotationAdvisor) { isAsyncAdvised = true; break; @@ -364,7 +364,8 @@ public class EnableAsyncTests { @EnableAsync static class AsyncConfigWithMockito { - @Bean @Lazy + @Bean + @Lazy public AsyncBean asyncBean() { return Mockito.mock(AsyncBean.class); } diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java index aef52f3801..da5a3af0ed 100644 --- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java +++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/ExpectedLookupTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -23,28 +23,29 @@ import javax.naming.NamingException; import org.springframework.jndi.JndiTemplate; /** - * Simple extension of the JndiTemplate class that always returns - * a given object. Very useful for testing. Effectively a mock object. + * Simple extension of the JndiTemplate class that always returns a given object. + * + *

Very useful for testing. Effectively a mock object. * * @author Rod Johnson * @author Juergen Hoeller */ public class ExpectedLookupTemplate extends JndiTemplate { - private final Map jndiObjects = new ConcurrentHashMap<>(); + private final Map jndiObjects = new ConcurrentHashMap<>(16); /** - * Construct a new JndiTemplate that will always return given objects - * for given names. To be populated through {@code addObject} calls. + * Construct a new JndiTemplate that will always return given objects for + * given names. To be populated through {@code addObject} calls. * @see #addObject(String, Object) */ public ExpectedLookupTemplate() { } /** - * Construct a new JndiTemplate that will always return the - * given object, but honour only requests for the given name. + * Construct a new JndiTemplate that will always return the given object, + * but honour only requests for the given name. * @param name the name the client is expected to look up * @param object the object that will be returned */ @@ -54,8 +55,7 @@ public class ExpectedLookupTemplate extends JndiTemplate { /** - * Add the given object to the list of JNDI objects that this - * template will expose. + * Add the given object to the list of JNDI objects that this template will expose. * @param name the name the client is expected to look up * @param object the object that will be returned */ @@ -63,11 +63,10 @@ public class ExpectedLookupTemplate extends JndiTemplate { this.jndiObjects.put(name, object); } - /** - * If the name is the expected name specified in the constructor, - * return the object provided in the constructor. If the name is - * unexpected, a respective NamingException gets thrown. + * If the name is the expected name specified in the constructor, return the + * object provided in the constructor. If the name is unexpected, a + * respective NamingException gets thrown. */ @Override public Object lookup(String name) throws NamingException { diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java index c4ba15c217..ef0d414b59 100644 --- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java +++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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,6 +33,7 @@ import javax.naming.OperationNotSupportedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -80,7 +81,9 @@ public class SimpleNamingContext implements Context { * Create a new naming context with the given naming root, * the given name/object map, and the JNDI environment entries. */ - public SimpleNamingContext(String root, Hashtable boundObjects, Hashtable env) { + public SimpleNamingContext( + String root, Hashtable boundObjects, @Nullable Hashtable env) { + this.root = root; this.boundObjects = boundObjects; if (env != null) { @@ -206,6 +209,7 @@ public class SimpleNamingContext implements Context { } @Override + @Nullable public Object addToEnvironment(String propName, Object propVal) { return this.environment.put(propName, propVal); } @@ -293,7 +297,7 @@ public class SimpleNamingContext implements Context { } - private static abstract class AbstractNamingEnumeration implements NamingEnumeration { + private abstract static class AbstractNamingEnumeration implements NamingEnumeration { private Iterator iterator; @@ -353,7 +357,7 @@ public class SimpleNamingContext implements Context { } - private static class NameClassPairEnumeration extends AbstractNamingEnumeration { + private static final class NameClassPairEnumeration extends AbstractNamingEnumeration { private NameClassPairEnumeration(SimpleNamingContext context, String root) throws NamingException { super(context, root); @@ -366,7 +370,7 @@ public class SimpleNamingContext implements Context { } - private static class BindingEnumeration extends AbstractNamingEnumeration { + private static final class BindingEnumeration extends AbstractNamingEnumeration { private BindingEnumeration(SimpleNamingContext context, String root) throws NamingException { super(context, root); diff --git a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java index 56fc6e802b..6c3a3d7780 100644 --- a/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java +++ b/spring-context/src/test/java/org/springframework/tests/mock/jndi/SimpleNamingContextBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -26,7 +26,10 @@ import javax.naming.spi.NamingManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.lang.Nullable; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.ReflectionUtils; /** * Simple implementation of a JNDI naming context builder. @@ -42,7 +45,7 @@ import org.springframework.util.ClassUtils; *

* *

Typical usage in bootstrap code: @@ -80,7 +83,8 @@ import org.springframework.util.ClassUtils; */ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder { - /** An instance of this class bound to JNDI */ + /** An instance of this class bound to JNDI. */ + @Nullable private static volatile SimpleNamingContextBuilder activated; private static boolean initialized = false; @@ -93,13 +97,14 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder * @return the current SimpleNamingContextBuilder instance, * or {@code null} if none */ + @Nullable public static SimpleNamingContextBuilder getCurrentContextBuilder() { return activated; } /** * If no SimpleNamingContextBuilder is already configuring JNDI, - * create and activate one. Otherwise take the existing activate + * create and activate one. Otherwise take the existing activated * SimpleNamingContextBuilder, clear it and return it. *

This is mainly intended for test suites that want to * reinitialize JNDI bindings from scratch repeatedly. @@ -107,17 +112,18 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder * to control JNDI bindings */ public static SimpleNamingContextBuilder emptyActivatedContextBuilder() throws NamingException { - if (activated != null) { + SimpleNamingContextBuilder builder = activated; + if (builder != null) { // Clear already activated context builder. - activated.clear(); + builder.clear(); } else { // Create and activate new context builder. - SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder(); + builder = new SimpleNamingContextBuilder(); // The activate() call will cause an assignment to the activated variable. builder.activate(); } - return activated; + return builder; } @@ -138,12 +144,10 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder logger.info("Activating simple JNDI environment"); synchronized (initializationLock) { if (!initialized) { - if (NamingManager.hasInitialContextFactoryBuilder()) { - throw new IllegalStateException( + Assert.state(!NamingManager.hasInitialContextFactoryBuilder(), "Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " + "Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " + "with no reset option. As a consequence, a JNDI provider must only be registered once per JVM."); - } NamingManager.setInitialContextFactoryBuilder(this); initialized = true; } @@ -192,7 +196,8 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder * @see SimpleNamingContext */ @Override - public InitialContextFactory createInitialContextFactory(Hashtable environment) { + @SuppressWarnings("unchecked") + public InitialContextFactory createInitialContextFactory(@Nullable Hashtable environment) { if (activated == null && environment != null) { Object icf = environment.get(Context.INITIAL_CONTEXT_FACTORY); if (icf != null) { @@ -212,22 +217,16 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder "Specified class does not implement [" + InitialContextFactory.class.getName() + "]: " + icf); } try { - return (InitialContextFactory) icfClass.newInstance(); + return (InitialContextFactory) ReflectionUtils.accessibleConstructor(icfClass).newInstance(); } catch (Throwable ex) { - throw new IllegalStateException("Cannot instantiate specified InitialContextFactory: " + icf, ex); + throw new IllegalStateException("Unable to instantiate specified InitialContextFactory: " + icf, ex); } } } // Default case... - return new InitialContextFactory() { - @Override - @SuppressWarnings("unchecked") - public Context getInitialContext(Hashtable environment) { - return new SimpleNamingContext("", boundObjects, (Hashtable) environment); - } - }; + return env -> new SimpleNamingContext("", this.boundObjects, (Hashtable) env); } } diff --git a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java index de27ed8207..2511858a97 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -199,7 +199,7 @@ public abstract class ObjectUtils { /** * Check whether the given array of enum constants contains a constant with the given name, * ignoring case when determining a match. - * @param enumValues the enum values to check, typically the product of a call to MyEnum.values() + * @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()} * @param constant the constant name to find (must not be null or empty string) * @return whether the constant has been found in the given array */ @@ -209,15 +209,14 @@ public abstract class ObjectUtils { /** * Check whether the given array of enum constants contains a constant with the given name. - * @param enumValues the enum values to check, typically the product of a call to MyEnum.values() + * @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()} * @param constant the constant name to find (must not be null or empty string) * @param caseSensitive whether case is significant in determining a match * @return whether the constant has been found in the given array */ public static boolean containsConstant(Enum[] enumValues, String constant, boolean caseSensitive) { for (Enum candidate : enumValues) { - if (caseSensitive ? - candidate.toString().equals(constant) : + if (caseSensitive ? candidate.toString().equals(constant) : candidate.toString().equalsIgnoreCase(constant)) { return true; } @@ -228,7 +227,7 @@ public abstract class ObjectUtils { /** * Case insensitive alternative to {@link Enum#valueOf(Class, String)}. * @param the concrete Enum type - * @param enumValues the array of all Enum constants in question, usually per Enum.values() + * @param enumValues the array of all Enum constants in question, usually per {@code Enum.values()} * @param constant the constant to get the enum value of * @throws IllegalArgumentException if the given constant is not found in the given array * of enum values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception. @@ -239,9 +238,8 @@ public abstract class ObjectUtils { return candidate; } } - throw new IllegalArgumentException( - String.format("constant [%s] does not exist in enum type %s", - constant, enumValues.getClass().getComponentType().getName())); + throw new IllegalArgumentException("Constant [" + constant + "] does not exist in enum type " + + enumValues.getClass().getComponentType().getName()); } /** @@ -251,7 +249,7 @@ public abstract class ObjectUtils { * @param obj the object to append * @return the new array (of the same component type; never {@code null}) */ - public static A[] addObjectToArray(@Nullable A[] array, @Nullable O obj) { + public static A[] addObjectToArray(@Nullable A[] array, @Nullable O obj) { Class compType = Object.class; if (array != null) { compType = array.getClass().getComponentType(); diff --git a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java index abd423c12f..e329fecfc1 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -25,7 +25,6 @@ import java.lang.reflect.UndeclaredThrowableException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -697,7 +696,7 @@ public abstract class ReflectionUtils { for (Method ifcMethod : ifc.getMethods()) { if (!Modifier.isAbstract(ifcMethod.getModifiers())) { if (result == null) { - result = new LinkedList<>(); + result = new ArrayList<>(); } result.add(ifcMethod); } diff --git a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java index 98f7e490e8..7054937975 100644 --- a/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ObjectUtilsTests.java @@ -45,6 +45,7 @@ public class ObjectUtilsTests { @Rule public final ExpectedException exception = ExpectedException.none(); + @Test public void isCheckedException() { assertTrue(ObjectUtils.isCheckedException(new Exception())); @@ -271,7 +272,7 @@ public class ObjectUtilsTests { @Test @Deprecated public void hashCodeWithLong() { - long lng = 883l; + long lng = 883L; int expected = (new Long(lng)).hashCode(); assertEquals(expected, ObjectUtils.hashCode(lng)); } @@ -489,12 +490,12 @@ public class ObjectUtilsTests { @Test public void nullSafeHashCodeWithLongArray() { - long lng = 7993l; + long lng = 7993L; int expected = 31 * 7 + (int) (lng ^ (lng >>> 32)); - lng = 84320l; + lng = 84320L; expected = 31 * expected + (int) (lng ^ (lng >>> 32)); - long[] array = {7993l, 84320l}; + long[] array = {7993L, 84320L}; int actual = ObjectUtils.nullSafeHashCode(array); assertEquals(expected, actual); @@ -715,7 +716,7 @@ public class ObjectUtilsTests { @Test public void nullSafeToStringWithLongArray() { - long[] array = {434l, 23423l}; + long[] array = {434L, 23423L}; assertEquals("{434, 23423}", ObjectUtils.nullSafeToString(array)); } @@ -807,7 +808,8 @@ public class ObjectUtilsTests { assertThat(ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "BAR"), is(Tropes.BAR)); exception.expect(IllegalArgumentException.class); - exception.expectMessage(is("constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes")); + exception.expectMessage( + is("Constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes")); ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "bogus"); } @@ -818,6 +820,6 @@ public class ObjectUtilsTests { } - enum Tropes { FOO, BAR, baz } + enum Tropes {FOO, BAR, baz} } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java index 5e386aa458..2b08f674cf 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -933,6 +933,7 @@ public interface JdbcOperations { * @param pss ParameterizedPreparedStatementSetter to use * @return an array containing for each batch another array containing the numbers of rows affected * by each update in the batch + * @since 3.1 */ int[][] batchUpdate(String sql, Collection batchArgs, int batchSize, ParameterizedPreparedStatementSetter pss) throws DataAccessException; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index a41eb1b715..6a93d085fc 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -984,11 +984,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { int[][] result = execute(sql, (PreparedStatementCallback) ps -> { List rowsAffected = new ArrayList<>(); try { - boolean batchSupported = true; - if (!JdbcUtils.supportsBatchUpdates(ps.getConnection())) { - batchSupported = false; - logger.warn("JDBC Driver does not support Batch updates; resorting to single statement execution"); - } + boolean batchSupported = JdbcUtils.supportsBatchUpdates(ps.getConnection()); int n = 0; for (T obj : batchArgs) { pss.setValues(ps, obj); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java index 347857a2f6..3505c29834 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java @@ -66,7 +66,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { public static final int DEFAULT_CACHE_LIMIT = 1024; /** Static evaluation context to reuse */ - private static EvaluationContext messageEvalContext = + private static final EvaluationContext messageEvalContext = SimpleEvaluationContext.forPropertyAccessors(new SimpMessageHeaderPropertyAccessor()).build(); @@ -130,7 +130,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { * @since 4.2 */ public void setSelectorHeaderName(@Nullable String selectorHeaderName) { - this.selectorHeaderName = StringUtils.hasText(selectorHeaderName) ? selectorHeaderName : null; + this.selectorHeaderName = (StringUtils.hasText(selectorHeaderName) ? selectorHeaderName : null); } /** @@ -248,7 +248,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { /** * A cache for destinations previously resolved via - * {@link DefaultSubscriptionRegistry#findSubscriptionsInternal(String, Message)} + * {@link DefaultSubscriptionRegistry#findSubscriptionsInternal(String, Message)}. */ private class DestinationCache { diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java b/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java index 3eeeb760a5..637683db64 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/ExpectedLookupTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -53,6 +53,7 @@ public class ExpectedLookupTemplate extends JndiTemplate { addObject(name, object); } + /** * Add the given object to the list of JNDI objects that this template will expose. * @param name the name the client is expected to look up diff --git a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java index 7b8c7b1b3b..6d3a9fb62f 100644 --- a/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java +++ b/spring-test/src/main/java/org/springframework/mock/jndi/SimpleNamingContextBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -104,7 +104,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder /** * If no SimpleNamingContextBuilder is already configuring JNDI, - * create and activate one. Otherwise take the existing activate + * create and activate one. Otherwise take the existing activated * SimpleNamingContextBuilder, clear it and return it. *

This is mainly intended for test suites that want to * reinitialize JNDI bindings from scratch repeatedly. @@ -226,7 +226,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder } // Default case... - return environment1 -> new SimpleNamingContext("", boundObjects, (Hashtable) environment1); + return env -> new SimpleNamingContext("", this.boundObjects, (Hashtable) env); } } diff --git a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java index 17f3394752..e66ed3fde0 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -962,9 +962,10 @@ public class HttpHeaders implements MultiValueMap, Serializable } /** - * Return the value of the required {@code Host} header. - *

If the header value does not contain a port, the returned - * {@linkplain InetSocketAddress#getPort() port} will be {@code 0}. + * Return the value of the {@code Host} header, if available. + *

If the header value does not contain a port, the + * {@linkplain InetSocketAddress#getPort() port} in the returned address will + * be {@code 0}. * @since 5.0 */ @Nullable diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java index 18f3e6605b..c3e226e175 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java @@ -110,6 +110,7 @@ public class Jaxb2XmlDecoder extends AbstractDecoder { @Override public Mono decodeToMono(Publisher inputStream, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map hints) { + return decode(inputStream, elementType, mimeType, hints).singleOrEmpty(); } diff --git a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java index 67dfb3ea05..20cc17bf54 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java +++ b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java @@ -80,7 +80,7 @@ public interface ServerWebExchange { @SuppressWarnings("unchecked") default T getRequiredAttribute(String name) { T value = getAttribute(name); - Assert.notNull(value, () -> "Required attribute '" + name + "' is missing."); + Assert.notNull(value, () -> "Required attribute '" + name + "' is missing"); return value; } @@ -114,7 +114,6 @@ public interface ServerWebExchange { /** * Return the form data from the body of the request if the Content-Type is * {@code "application/x-www-form-urlencoded"} or an empty map otherwise. - * *

Note: calling this method causes the request body to * be read and parsed in full and the resulting {@code MultiValueMap} is * cached so that this method is safe to call more than once. @@ -124,7 +123,6 @@ public interface ServerWebExchange { /** * Return the parts of a multipart request if the Content-Type is * {@code "multipart/form-data"} or an empty map otherwise. - * *

Note: calling this method causes the request body to * be read and parsed in full and the resulting {@code MultiValueMap} is * cached so that this method is safe to call more than once. @@ -140,8 +138,7 @@ public interface ServerWebExchange { /** * Return the {@link ApplicationContext} associated with the web application, * if it was initialized with one via - * {@link org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext - * WebHttpHandlerBuilder#applicationContext}. + * {@link org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext(ApplicationContext)}. * @since 5.0.3 * @see org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext(ApplicationContext) */ 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 05a636c99b..b5c3ae6ea1 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 @@ -186,16 +186,14 @@ public abstract class BodyInserters { } /** - * Return a {@link FormInserter} that writes the given {@code MultiValueMap} + * Return a {@link FormInserter} to write the given {@code MultiValueMap} * as URL-encoded form data. The returned inserter allows for additional * entries to be added via {@link FormInserter#with(String, Object)}. - * *

Note that you can also use the {@code syncBody(Object)} method in the * request builders of both the {@code WebClient} and {@code WebTestClient}. * In that case the setting of the request content type is also not required, * just be sure the map contains String values only or otherwise it would be * interpreted as a multipart request. - * * @param formData the form data to write to the output message * @return the inserter that allows adding more form data */ @@ -204,7 +202,7 @@ public abstract class BodyInserters { } /** - * Return a {@link FormInserter} that writes the given key-value pair as + * Return a {@link FormInserter} to write the given key-value pair as * URL-encoded form data. The returned inserter allows for additional * entries to be added via {@link FormInserter#with(String, Object)}. * @param name the key to add to the form @@ -218,7 +216,7 @@ public abstract class BodyInserters { } /** - * Return a {@link MultipartInserter} that writes the given + * Return a {@link MultipartInserter} to write the given * {@code MultiValueMap} as multipart data. Values in the map can be an * Object or an {@link HttpEntity}. *

Note that you can also build the multipart data externally with @@ -234,7 +232,7 @@ public abstract class BodyInserters { } /** - * Return a {@link MultipartInserter} that writes the given parts, + * Return a {@link MultipartInserter} to write the given parts, * as multipart data. Values in the map can be an Object or an * {@link HttpEntity}. *

Note that you can also build the multipart data externally with @@ -251,7 +249,7 @@ public abstract class BodyInserters { } /** - * Return a {@link MultipartInserter} that writes the given asynchronous parts, + * Return a {@link MultipartInserter} to write the given asynchronous parts, * as multipart data. *

Note that you can also build the multipart data externally with * {@link MultipartBodyBuilder}, and pass the resulting map directly to the @@ -286,11 +284,10 @@ public abstract class BodyInserters { } /** - * Return a {@code BodyInserter} that writes the given - * {@code Publisher} to the body. + * Inserter to write the given {@code Publisher} to the body. * @param publisher the data buffer publisher to write * @param the type of the publisher - * @return a {@code BodyInserter} that writes directly to the body + * @return the inserter to write directly to the body * @see ReactiveHttpOutputMessage#writeWith(Publisher) */ public static > BodyInserter fromDataBuffers( diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java index 6dfbab0965..5a2f582d7c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java @@ -62,13 +62,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { private BodyInserter body = BodyInserters.empty(); - public DefaultClientRequestBuilder(HttpMethod method, URI url) { - Assert.notNull(method, "HttpMethod must not be null"); - Assert.notNull(url, "URI must not be null"); - this.method = method; - this.url = url; - } - public DefaultClientRequestBuilder(ClientRequest other) { Assert.notNull(other, "ClientRequest must not be null"); this.method = other.method(); @@ -79,17 +72,24 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { body(other.body()); } + public DefaultClientRequestBuilder(HttpMethod method, URI url) { + Assert.notNull(method, "HttpMethod must not be null"); + Assert.notNull(url, "URI must not be null"); + this.method = method; + this.url = url; + } + @Override public ClientRequest.Builder method(HttpMethod method) { - Assert.notNull(method, "'method' must not be null"); + Assert.notNull(method, "HttpMethod must not be null"); this.method = method; return this; } @Override public ClientRequest.Builder url(URI url) { - Assert.notNull(url, "'url' must not be null"); + Assert.notNull(url, "URI must not be null"); this.url = url; return this; } @@ -124,9 +124,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { @Override public > ClientRequest.Builder body(P publisher, Class elementClass) { - Assert.notNull(publisher, "'publisher' must not be null"); - Assert.notNull(elementClass, "'elementClass' must not be null"); - this.body = BodyInserters.fromPublisher(publisher, elementClass); return this; } @@ -135,9 +132,6 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { public > ClientRequest.Builder body( P publisher, ParameterizedTypeReference typeReference) { - Assert.notNull(publisher, "'publisher' must not be null"); - Assert.notNull(typeReference, "'typeReference' must not be null"); - this.body = BodyInserters.fromPublisher(publisher, typeReference); return this; }