From 9198e037c156faca7f85073879a3af4aa2c47d9b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 3 May 2019 18:02:53 +0200 Subject: [PATCH] Consistent use of StringUtils.hasLength(String) vs isEmpty(Object) --- .../org/springframework/util/StringUtils.java | 13 +++++- .../jdbc/core/JdbcTemplate.java | 2 +- .../org/springframework/http/HttpHeaders.java | 2 +- .../reactive/UndertowServerHttpRequest.java | 25 +++++------ .../RequestParamMethodArgumentResolver.java | 6 +-- .../web/util/DefaultUriBuilderFactory.java | 13 ++---- .../resource/VersionResourceResolver.java | 4 +- .../reactive/result/view/RedirectView.java | 44 +++++++++---------- .../annotation/MvcUriComponentsBuilder.java | 11 +++-- .../PathVariableMethodArgumentResolver.java | 4 +- .../resource/VersionResourceResolver.java | 4 +- .../support/ServletUriComponentsBuilder.java | 4 +- .../web/servlet/view/RedirectView.java | 2 +- .../view/json/MappingJackson2JsonView.java | 4 +- .../SubProtocolWebSocketHandler.java | 4 +- .../AbstractHttpSendingTransportHandler.java | 6 +-- .../session/WebSocketServerSockJsSession.java | 4 +- 17 files changed, 76 insertions(+), 76 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 215653ba9b..04403a3692 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -75,15 +75,20 @@ public abstract class StringUtils { //--------------------------------------------------------------------- /** - * Check whether the given {@code String} is empty. + * Check whether the given object (possibly a {@code String}) is empty. + * This is effectly a shortcut for {@code !hasLength(String)}. *

This method accepts any Object as an argument, comparing it to * {@code null} and the empty String. As a consequence, this method * will never return {@code true} for a non-null non-String object. *

The Object signature is useful for general attribute handling code * that commonly deals with Strings but generally has to iterate over * Objects since attributes may e.g. be primitive value objects as well. - * @param str the candidate String + *

Note: If the object is typed to {@code String} upfront, prefer + * {@link #hasLength(String)} or {@link #hasText(String)} instead. + * @param str the candidate object (possibly a {@code String}) * @since 3.2.1 + * @see #hasLength(String) + * @see #hasText(String) */ public static boolean isEmpty(@Nullable Object str) { return (str == null || "".equals(str)); @@ -136,6 +141,8 @@ public abstract class StringUtils { * @param str the {@code CharSequence} to check (may be {@code null}) * @return {@code true} if the {@code CharSequence} is not {@code null}, * its length is greater than 0, and it does not contain whitespace only + * @see #hasText(String) + * @see #hasLength(CharSequence) * @see Character#isWhitespace */ public static boolean hasText(@Nullable CharSequence str) { @@ -151,6 +158,8 @@ public abstract class StringUtils { * @return {@code true} if the {@code String} is not {@code null}, its * length is greater than 0, and it does not contain whitespace only * @see #hasText(CharSequence) + * @see #hasLength(String) + * @see Character#isWhitespace */ public static boolean hasText(@Nullable String str) { return (str != null && !str.isEmpty() && containsText(str)); 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 08b73f9445..819fff30f0 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 @@ -564,7 +564,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } private String appendSql(@Nullable String sql, String statement) { - return (StringUtils.isEmpty(sql) ? statement : sql + "; " + statement); + return (StringUtils.hasLength(sql) ? sql + "; " + statement : statement); } @Override 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 33f2ca1e94..e452e21452 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -700,7 +700,7 @@ public class HttpHeaders implements MultiValueMap, Serializable */ public Set getAllow() { String value = getFirst(ALLOW); - if (!StringUtils.isEmpty(value)) { + if (StringUtils.hasLength(value)) { String[] tokens = StringUtils.tokenizeToStringArray(value, ","); List result = new ArrayList<>(tokens.length); for (String token : tokens) { diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java index c18681565e..4ef141635a 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.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. @@ -70,10 +70,10 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { } private static URI initUri(HttpServerExchange exchange) throws URISyntaxException { - Assert.notNull(exchange, "HttpServerExchange is required."); + Assert.notNull(exchange, "HttpServerExchange is required"); String requestURL = exchange.getRequestURL(); String query = exchange.getQueryString(); - String requestUriAndQuery = StringUtils.isEmpty(query) ? requestURL : requestURL + "?" + query; + String requestUriAndQuery = (StringUtils.hasLength(query) ? requestURL + "?" + query : requestURL); return new URI(requestUriAndQuery); } @@ -171,12 +171,10 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { boolean release = true; try { ByteBuffer byteBuffer = pooledByteBuffer.getBuffer(); - int read = this.channel.read(byteBuffer); if (logger.isTraceEnabled()) { logger.trace("Channel read returned " + read + (read != -1 ? " bytes" : "")); } - if (read > 0) { byteBuffer.flip(); DataBuffer dataBuffer = this.bufferFactory.wrap(byteBuffer); @@ -187,7 +185,8 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { onAllDataRead(); } return null; - } finally { + } + finally { if (release && pooledByteBuffer.isOpen()) { pooledByteBuffer.close(); } @@ -200,6 +199,7 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { } } + private static class UndertowDataBuffer implements PooledDataBuffer { private final DataBuffer dataBuffer; @@ -299,8 +299,7 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { } @Override - public DataBuffer read(byte[] destination, int offset, - int length) { + public DataBuffer read(byte[] destination, int offset, int length) { return this.dataBuffer.read(destination, offset, length); } @@ -315,20 +314,17 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { } @Override - public DataBuffer write(byte[] source, int offset, - int length) { + public DataBuffer write(byte[] source, int offset, int length) { return this.dataBuffer.write(source, offset, length); } @Override - public DataBuffer write( - DataBuffer... buffers) { + public DataBuffer write(DataBuffer... buffers) { return this.dataBuffer.write(buffers); } @Override - public DataBuffer write( - ByteBuffer... byteBuffers) { + public DataBuffer write(ByteBuffer... byteBuffers) { return this.dataBuffer.write(byteBuffers); } @@ -362,4 +358,5 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { return this.dataBuffer.asOutputStream(); } } + } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java index 5682353a8d..0ff9a4f648 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.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. @@ -213,8 +213,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class); - String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ? - parameter.getParameterName() : requestParam.name()); + String name = (requestParam != null && StringUtils.hasLength(requestParam.name()) ? + requestParam.name() : parameter.getParameterName()); Assert.state(name != null, "Unresolvable parameter name"); if (value == null) { diff --git a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java index b9aaa2652a..b6660fe8fd 100644 --- a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.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,7 +33,6 @@ import org.springframework.util.StringUtils; *

Provides options to create {@link UriBuilder} instances with a common * base URI, alternative encoding mode strategies, among others. * - * * @author Rossen Stoyanchev * @since 5.0 * @see UriComponentsBuilder @@ -222,31 +221,27 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { private final UriComponentsBuilder uriComponentsBuilder; - public DefaultUriBuilder(String uriTemplate) { this.uriComponentsBuilder = initUriComponentsBuilder(uriTemplate); } private UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) { UriComponentsBuilder result; - if (StringUtils.isEmpty(uriTemplate)) { - result = baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance(); + if (!StringUtils.hasLength(uriTemplate)) { + result = (baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance()); } else if (baseUri != null) { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriTemplate); UriComponents uri = builder.build(); - result = uri.getHost() == null ? baseUri.cloneBuilder().uriComponents(uri) : builder; + result = (uri.getHost() == null ? baseUri.cloneBuilder().uriComponents(uri) : builder); } else { result = UriComponentsBuilder.fromUriString(uriTemplate); } - if (encodingMode.equals(EncodingMode.TEMPLATE_AND_VALUES)) { result.encode(); } - parsePathIfNecessary(result); - return result; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java index 3c660a2722..93c5c4cfac 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.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. @@ -172,7 +172,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { } String candidate = versionStrategy.extractVersion(requestPath); - if (StringUtils.isEmpty(candidate)) { + if (!StringUtils.hasLength(candidate)) { if (logger.isTraceEnabled()) { logger.trace("No version found in path \"" + requestPath + "\""); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java index a9e7cc90eb..4b3ae4f0b5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.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. @@ -44,8 +44,8 @@ import org.springframework.web.util.UriUtils; * URI template in which case the URI template variables will be replaced with * values from the model or with URI variables from the current request. * - *

By default {@link HttpStatus#SEE_OTHER} is used but alternate status - * codes may be via constructor or setters arguments. + *

By default {@link HttpStatus#SEE_OTHER} is used but alternate status codes + * may be via constructor or setters arguments. * * @author Sebastien Deleuze * @author Rossen Stoyanchev @@ -56,10 +56,10 @@ public class RedirectView extends AbstractUrlBasedView { private static final Pattern URI_TEMPLATE_VARIABLE_PATTERN = Pattern.compile("\\{([^/]+?)\\}"); - private boolean contextRelative = true; - private HttpStatus statusCode = HttpStatus.SEE_OTHER; + private boolean contextRelative = true; + private boolean propagateQuery = false; @Nullable @@ -91,22 +91,6 @@ public class RedirectView extends AbstractUrlBasedView { } - /** - * Whether to interpret a given redirect URLs that starts with a slash ("/") - * as relative to the current context path ({@code true}, the default) or to - * the web server root ({@code false}). - */ - public void setContextRelative(boolean contextRelative) { - this.contextRelative = contextRelative; - } - - /** - * Whether to interpret URLs as relative to the current context path. - */ - public boolean isContextRelative() { - return this.contextRelative; - } - /** * Set an alternate redirect status code such as * {@link HttpStatus#TEMPORARY_REDIRECT} or @@ -124,6 +108,22 @@ public class RedirectView extends AbstractUrlBasedView { return this.statusCode; } + /** + * Whether to interpret a given redirect URLs that starts with a slash ("/") + * as relative to the current context path ({@code true}, the default) or to + * the web server root ({@code false}). + */ + public void setContextRelative(boolean contextRelative) { + this.contextRelative = contextRelative; + } + + /** + * Whether to interpret URLs as relative to the current context path. + */ + public boolean isContextRelative() { + return this.contextRelative; + } + /** * Whether to append the query string of the current URL to the redirect URL * ({@code true}) or not ({@code false}, the default). @@ -309,7 +309,7 @@ public class RedirectView extends AbstractUrlBasedView { return false; } String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost(); - if (StringUtils.isEmpty(targetHost)) { + if (!StringUtils.hasLength(targetHost)) { return false; } for (String host : this.hosts) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index 6cad0be8b6..e51fb9e6a6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.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. @@ -357,11 +357,10 @@ public class MvcUriComponentsBuilder { RequestMappingInfoHandlerMapping handlerMapping = getRequestMappingInfoHandlerMapping(); List handlerMethods = handlerMapping.getHandlerMethodsForMappingName(name); if (handlerMethods == null) { - throw new IllegalArgumentException("Mapping mappingName not found: " + name); + throw new IllegalArgumentException("Mapping not found: " + name); } if (handlerMethods.size() != 1) { - throw new IllegalArgumentException("No unique match for mapping mappingName " + - name + ": " + handlerMethods); + throw new IllegalArgumentException("No unique match for mapping " + name + ": " + handlerMethods); } HandlerMethod handlerMethod = handlerMethods.get(0); Class controllerType = handlerMethod.getBeanType(); @@ -440,7 +439,7 @@ public class MvcUriComponentsBuilder { return "/"; } String[] paths = requestMapping.path(); - if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) { + if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) { return "/"; } if (paths.length > 1 && logger.isWarnEnabled()) { @@ -456,7 +455,7 @@ public class MvcUriComponentsBuilder { throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString()); } String[] paths = requestMapping.path(); - if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) { + if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) { return "/"; } if (paths.length > 1 && logger.isWarnEnabled()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java index 50652bbe90..526eb0355a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -125,7 +125,7 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod } PathVariable ann = parameter.getParameterAnnotation(PathVariable.class); - String name = (ann != null && !StringUtils.isEmpty(ann.value()) ? ann.value() : parameter.getParameterName()); + String name = (ann != null && StringUtils.hasLength(ann.value()) ? ann.value() : parameter.getParameterName()); String formatted = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value); uriVariables.put(name, formatted); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java index 21759702a6..3b22411627 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.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. @@ -168,7 +168,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { } String candidateVersion = versionStrategy.extractVersion(requestPath); - if (StringUtils.isEmpty(candidateVersion)) { + if (!StringUtils.hasLength(candidateVersion)) { if (logger.isTraceEnabled()) { logger.trace("No version found in path \"" + requestPath + "\""); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java index a942cc15b8..f29fb2fc5c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java @@ -187,7 +187,7 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder { String forwardedPrefix = getForwardedPrefix(request); if (forwardedPrefix != null) { String contextPath = request.getContextPath(); - if (!StringUtils.isEmpty(contextPath) && !contextPath.equals("/") && path.startsWith(contextPath)) { + if (StringUtils.hasLength(contextPath) && !contextPath.equals("/") && path.startsWith(contextPath)) { path = path.substring(contextPath.length()); } path = forwardedPrefix + path; @@ -285,7 +285,7 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder { String extension = null; if (this.originalPath != null) { extension = UriUtils.extractFileExtension(this.originalPath); - if (!StringUtils.isEmpty(extension)) { + if (StringUtils.hasLength(extension)) { int end = this.originalPath.length() - (extension.length() + 1); replacePath(this.originalPath.substring(0, end)); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java index c6ee5ec016..77313e7cee 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java @@ -650,7 +650,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView { return false; } String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost(); - if (StringUtils.isEmpty(targetHost)) { + if (!StringUtils.hasLength(targetHost)) { return false; } for (String host : getHosts()) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java index f32eada4b0..24705f17f2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/view/json/MappingJackson2JsonView.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. @@ -190,7 +190,7 @@ public class MappingJackson2JsonView extends AbstractJackson2View { if (this.jsonpParameterNames != null) { for (String name : this.jsonpParameterNames) { String value = request.getParameter(name); - if (StringUtils.isEmpty(value)) { + if (!StringUtils.hasLength(value)) { continue; } if (!isValidJsonpQueryParam(value)) { 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 4c1928e363..713782a476 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 @@ -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. @@ -408,7 +408,7 @@ public class SubProtocolWebSocketHandler } SubProtocolHandler handler; - if (!StringUtils.isEmpty(protocol)) { + if (StringUtils.hasLength(protocol)) { handler = this.protocolHandlerLookup.get(protocol); if (handler == null) { throw new IllegalStateException( diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java index 5e9cfb81e5..0aa17c5552 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -46,7 +46,7 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp implements SockJsSessionFactory { /** - * Pattern for validating jsonp callback parameter values. + * Pattern for validating callback parameter values. */ private static final Pattern CALLBACK_PARAM_PATTERN = Pattern.compile("[0-9A-Za-z_\\.]*"); @@ -118,7 +118,7 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp String query = request.getURI().getQuery(); MultiValueMap params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams(); String value = params.getFirst("c"); - if (StringUtils.isEmpty(value)) { + if (!StringUtils.hasLength(value)) { return null; } String result = UriUtils.decode(value, StandardCharsets.UTF_8); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java index fb521288a1..35d73332b5 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 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. @@ -179,7 +179,7 @@ public class WebSocketServerSockJsSession extends AbstractSockJsSession implemen public void handleMessage(TextMessage message, WebSocketSession wsSession) throws Exception { String payload = message.getPayload(); - if (StringUtils.isEmpty(payload)) { + if (!StringUtils.hasLength(payload)) { return; } String[] messages;