From d00e1c5e4fbf0c9affa1fa8314be172e4666e5a9 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 10 Feb 2018 21:35:46 +0100 Subject: [PATCH] Polishing --- .../java/org/springframework/jmx/support/JmxUtils.java | 9 ++++----- .../java/org/springframework/validation/DataBinder.java | 5 +++-- .../web/socket/sockjs/client/UndertowXhrTransport.java | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java index daae67fe4ee..2222712d8f1 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/JmxUtils.java @@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.jmx.MBeanServerNotFoundException; import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -69,8 +70,7 @@ public abstract class JmxUtils { * {@code MBeanServer} can be found. Logs a warning if more than one * {@code MBeanServer} found, returning the first one from the list. * @return the {@code MBeanServer} if found - * @throws org.springframework.jmx.MBeanServerNotFoundException - * if no {@code MBeanServer} could be found + * @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer */ public static MBeanServer locateMBeanServer() throws MBeanServerNotFoundException { @@ -85,8 +85,7 @@ public abstract class JmxUtils { * If this parameter is {@code null}, all registered MBeanServers are considered. * If the empty String is given, the platform MBeanServer will be returned. * @return the {@code MBeanServer} if found - * @throws org.springframework.jmx.MBeanServerNotFoundException - * if no {@code MBeanServer} could be found + * @throws MBeanServerNotFoundException if no {@code MBeanServer} could be found * @see javax.management.MBeanServerFactory#findMBeanServer(String) */ public static MBeanServer locateMBeanServer(@Nullable String agentId) throws MBeanServerNotFoundException { @@ -95,7 +94,7 @@ public abstract class JmxUtils { // null means any registered server, but "" specifically means the platform server if (!"".equals(agentId)) { List servers = MBeanServerFactory.findMBeanServer(agentId); - if (servers != null && !servers.isEmpty()) { + if (!CollectionUtils.isEmpty(servers)) { // Check to see if an MBeanServer is registered. if (servers.size() > 1 && logger.isWarnEnabled()) { logger.warn("Found more than one MBeanServer instance" + diff --git a/spring-context/src/main/java/org/springframework/validation/DataBinder.java b/spring-context/src/main/java/org/springframework/validation/DataBinder.java index 355d0d2bd13..9a9972f9139 100644 --- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java +++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java @@ -535,9 +535,10 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { } private void assertValidators(Validator... validators) { + Object target = getTarget(); for (Validator validator : validators) { - if (validator != null && (getTarget() != null && !validator.supports(getTarget().getClass()))) { - throw new IllegalStateException("Invalid target for Validator [" + validator + "]: " + getTarget()); + if (validator != null && (target != null && !validator.supports(target.getClass()))) { + throw new IllegalStateException("Invalid target for Validator [" + validator + "]: " + target); } } } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/UndertowXhrTransport.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/UndertowXhrTransport.java index 9be23d7769f..c2611c7e76f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/UndertowXhrTransport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/UndertowXhrTransport.java @@ -54,6 +54,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; import org.springframework.util.concurrent.SettableListenableFuture; import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.socket.CloseStatus; @@ -276,7 +277,7 @@ public class UndertowXhrTransport extends AbstractXhrTransport { try { ClientRequest request = new ClientRequest().setMethod(method).setPath(url.getPath()); request.getRequestHeaders().add(HttpString.tryFromString(HttpHeaders.HOST), url.getHost()); - if (body != null && !body.isEmpty()) { + if (StringUtils.hasLength(body)) { HttpString headerName = HttpString.tryFromString(HttpHeaders.CONTENT_LENGTH); request.getRequestHeaders().add(headerName, body.length()); }