Skip to content

Commit f0f6af2

Browse files
committed
Merge branch '5.1.x'
2 parents 8304653 + ea4a174 commit f0f6af2

File tree

20 files changed

+73
-68
lines changed

20 files changed

+73
-68
lines changed

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,20 @@ public abstract class StringUtils {
7676
//---------------------------------------------------------------------
7777

7878
/**
79-
* Check whether the given {@code String} is empty.
79+
* Check whether the given object (possibly a {@code String}) is empty.
80+
* This is effectly a shortcut for {@code !hasLength(String)}.
8081
* <p>This method accepts any Object as an argument, comparing it to
8182
* {@code null} and the empty String. As a consequence, this method
8283
* will never return {@code true} for a non-null non-String object.
8384
* <p>The Object signature is useful for general attribute handling code
8485
* that commonly deals with Strings but generally has to iterate over
8586
* Objects since attributes may e.g. be primitive value objects as well.
86-
* @param str the candidate String
87+
* <p><b>Note: If the object is typed to {@code String} upfront, prefer
88+
* {@link #hasLength(String)} or {@link #hasText(String)} instead.</b>
89+
* @param str the candidate object (possibly a {@code String})
8790
* @since 3.2.1
91+
* @see #hasLength(String)
92+
* @see #hasText(String)
8893
*/
8994
public static boolean isEmpty(@Nullable Object str) {
9095
return (str == null || "".equals(str));
@@ -103,7 +108,8 @@ public static boolean isEmpty(@Nullable Object str) {
103108
* </pre>
104109
* @param str the {@code CharSequence} to check (may be {@code null})
105110
* @return {@code true} if the {@code CharSequence} is not {@code null} and has length
106-
* @see #hasText(String)
111+
* @see #hasLength(String)
112+
* @see #hasText(CharSequence)
107113
*/
108114
public static boolean hasLength(@Nullable CharSequence str) {
109115
return (str != null && str.length() > 0);
@@ -137,6 +143,8 @@ public static boolean hasLength(@Nullable String str) {
137143
* @param str the {@code CharSequence} to check (may be {@code null})
138144
* @return {@code true} if the {@code CharSequence} is not {@code null},
139145
* its length is greater than 0, and it does not contain whitespace only
146+
* @see #hasText(String)
147+
* @see #hasLength(CharSequence)
140148
* @see Character#isWhitespace
141149
*/
142150
public static boolean hasText(@Nullable CharSequence str) {
@@ -152,6 +160,8 @@ public static boolean hasText(@Nullable CharSequence str) {
152160
* @return {@code true} if the {@code String} is not {@code null}, its
153161
* length is greater than 0, and it does not contain whitespace only
154162
* @see #hasText(CharSequence)
163+
* @see #hasLength(String)
164+
* @see Character#isWhitespace
155165
*/
156166
public static boolean hasText(@Nullable String str) {
157167
return (str != null && !str.isEmpty() && containsText(str));

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public int[] doInStatement(Statement stmt) throws SQLException, DataAccessExcept
576576
}
577577

578578
private String appendSql(@Nullable String sql, String statement) {
579-
return (StringUtils.isEmpty(sql) ? statement : sql + "; " + statement);
579+
return (StringUtils.hasLength(sql) ? sql + "; " + statement : statement);
580580
}
581581

582582
@Override

spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAspectSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ protected TransactionInfo prepareTransactionInfo(@Nullable PlatformTransactionMa
581581
// The TransactionInfo.hasTransaction() method will return false. We created it only
582582
// to preserve the integrity of the ThreadLocal stack maintained in this class.
583583
if (logger.isTraceEnabled()) {
584-
logger.trace("Don't need to create transaction for [" + joinpointIdentification +
585-
"]: This method isn't transactional.");
584+
logger.trace("No need to create transaction for [" + joinpointIdentification +
585+
"]: This method is not transactional.");
586586
}
587587
}
588588

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ public void setAllow(Set<HttpMethod> allowedMethods) {
704704
*/
705705
public Set<HttpMethod> getAllow() {
706706
String value = getFirst(ALLOW);
707-
if (!StringUtils.isEmpty(value)) {
707+
if (StringUtils.hasLength(value)) {
708708
String[] tokens = StringUtils.tokenizeToStringArray(value, ",");
709709
List<HttpMethod> result = new ArrayList<>(tokens.length);
710710
for (String token : tokens) {

spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,15 @@ public UndertowServerHttpRequest(HttpServerExchange exchange, DataBufferFactory
7171
}
7272

7373
private static URI initUri(HttpServerExchange exchange) throws URISyntaxException {
74-
Assert.notNull(exchange, "HttpServerExchange is required.");
74+
Assert.notNull(exchange, "HttpServerExchange is required");
7575
String requestURL = exchange.getRequestURL();
7676
String query = exchange.getQueryString();
77-
String requestUriAndQuery = StringUtils.isEmpty(query) ? requestURL : requestURL + "?" + query;
77+
String requestUriAndQuery = (StringUtils.hasLength(query) ? requestURL + "?" + query : requestURL);
7878
return new URI(requestUriAndQuery);
7979
}
8080

8181
private static HttpHeaders initHeaders(HttpServerExchange exchange) {
82-
UndertowHeadersAdapter headersMap =
83-
new UndertowHeadersAdapter(exchange.getRequestHeaders());
84-
return new HttpHeaders(headersMap);
82+
return new HttpHeaders(new UndertowHeadersAdapter(exchange.getRequestHeaders()));
8583
}
8684

8785
@Override

spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMethodArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ public void contributeMethodArgument(MethodParameter parameter, @Nullable Object
214214
}
215215

216216
RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
217-
String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ?
218-
parameter.getParameterName() : requestParam.name());
217+
String name = (requestParam != null && StringUtils.hasLength(requestParam.name()) ?
218+
requestParam.name() : parameter.getParameterName());
219219
Assert.state(name != null, "Unresolvable parameter name");
220220

221221
parameter = parameter.nestedIfOptional();

spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,7 +33,6 @@
3333
* <p>Provides options to create {@link UriBuilder} instances with a common
3434
* base URI, alternative encoding mode strategies, among others.
3535
*
36-
*
3736
* @author Rossen Stoyanchev
3837
* @since 5.0
3938
* @see UriComponentsBuilder
@@ -222,31 +221,27 @@ private class DefaultUriBuilder implements UriBuilder {
222221

223222
private final UriComponentsBuilder uriComponentsBuilder;
224223

225-
226224
public DefaultUriBuilder(String uriTemplate) {
227225
this.uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
228226
}
229227

230228
private UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) {
231229
UriComponentsBuilder result;
232-
if (StringUtils.isEmpty(uriTemplate)) {
233-
result = baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance();
230+
if (!StringUtils.hasLength(uriTemplate)) {
231+
result = (baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance());
234232
}
235233
else if (baseUri != null) {
236234
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriTemplate);
237235
UriComponents uri = builder.build();
238-
result = uri.getHost() == null ? baseUri.cloneBuilder().uriComponents(uri) : builder;
236+
result = (uri.getHost() == null ? baseUri.cloneBuilder().uriComponents(uri) : builder);
239237
}
240238
else {
241239
result = UriComponentsBuilder.fromUriString(uriTemplate);
242240
}
243-
244241
if (encodingMode.equals(EncodingMode.TEMPLATE_AND_VALUES)) {
245242
result.encode();
246243
}
247-
248244
parsePathIfNecessary(result);
249-
250245
return result;
251246
}
252247

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeStrategies.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public interface ExchangeStrategies {
5151
// Static builder methods
5252

5353
/**
54-
* Return a new {@code ExchangeStrategies} with default configuration
54+
* Return an {@code ExchangeStrategies} instance with default configuration
5555
* provided by {@link ClientCodecConfigurer}.
5656
*/
5757
static ExchangeStrategies withDefaults() {

spring-webflux/src/main/java/org/springframework/web/reactive/resource/VersionResourceResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -172,7 +172,7 @@ private Mono<Resource> resolveVersionedResource(@Nullable ServerWebExchange exch
172172
}
173173

174174
String candidate = versionStrategy.extractVersion(requestPath);
175-
if (StringUtils.isEmpty(candidate)) {
175+
if (!StringUtils.hasLength(candidate)) {
176176
return Mono.empty();
177177
}
178178

spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,8 +44,8 @@
4444
* URI template in which case the URI template variables will be replaced with
4545
* values from the model or with URI variables from the current request.
4646
*
47-
* <p>By default {@link HttpStatus#SEE_OTHER} is used but alternate status
48-
* codes may be via constructor or setters arguments.
47+
* <p>By default {@link HttpStatus#SEE_OTHER} is used but alternate status codes
48+
* may be via constructor or setters arguments.
4949
*
5050
* @author Sebastien Deleuze
5151
* @author Rossen Stoyanchev
@@ -56,10 +56,10 @@ public class RedirectView extends AbstractUrlBasedView {
5656
private static final Pattern URI_TEMPLATE_VARIABLE_PATTERN = Pattern.compile("\\{([^/]+?)\\}");
5757

5858

59-
private boolean contextRelative = true;
60-
6159
private HttpStatus statusCode = HttpStatus.SEE_OTHER;
6260

61+
private boolean contextRelative = true;
62+
6363
private boolean propagateQuery = false;
6464

6565
@Nullable
@@ -91,22 +91,6 @@ public RedirectView(String redirectUrl, HttpStatus statusCode) {
9191
}
9292

9393

94-
/**
95-
* Whether to interpret a given redirect URLs that starts with a slash ("/")
96-
* as relative to the current context path ({@code true}, the default) or to
97-
* the web server root ({@code false}).
98-
*/
99-
public void setContextRelative(boolean contextRelative) {
100-
this.contextRelative = contextRelative;
101-
}
102-
103-
/**
104-
* Whether to interpret URLs as relative to the current context path.
105-
*/
106-
public boolean isContextRelative() {
107-
return this.contextRelative;
108-
}
109-
11094
/**
11195
* Set an alternate redirect status code such as
11296
* {@link HttpStatus#TEMPORARY_REDIRECT} or
@@ -124,6 +108,22 @@ public HttpStatus getStatusCode() {
124108
return this.statusCode;
125109
}
126110

111+
/**
112+
* Whether to interpret a given redirect URLs that starts with a slash ("/")
113+
* as relative to the current context path ({@code true}, the default) or to
114+
* the web server root ({@code false}).
115+
*/
116+
public void setContextRelative(boolean contextRelative) {
117+
this.contextRelative = contextRelative;
118+
}
119+
120+
/**
121+
* Whether to interpret URLs as relative to the current context path.
122+
*/
123+
public boolean isContextRelative() {
124+
return this.contextRelative;
125+
}
126+
127127
/**
128128
* Whether to append the query string of the current URL to the redirect URL
129129
* ({@code true}) or not ({@code false}, the default).
@@ -309,7 +309,7 @@ protected boolean isRemoteHost(String targetUrl) {
309309
return false;
310310
}
311311
String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost();
312-
if (StringUtils.isEmpty(targetHost)) {
312+
if (!StringUtils.hasLength(targetHost)) {
313313
return false;
314314
}
315315
for (String host : this.hosts) {

spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,11 +963,12 @@ private void logRequest(HttpServletRequest request) {
963963
params = (request.getParameterMap().isEmpty() ? "" : "masked");
964964
}
965965

966-
String query = StringUtils.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString();
966+
String queryString = request.getQueryString();
967+
String queryClause = (StringUtils.hasLength(queryString) ? "?" + queryString : "");
967968
String dispatchType = (!request.getDispatcherType().equals(DispatcherType.REQUEST) ?
968969
"\"" + request.getDispatcherType().name() + "\" dispatch for " : "");
969970
String message = (dispatchType + request.getMethod() + " \"" + getRequestUri(request) +
970-
query + "\", parameters={" + params + "}");
971+
queryClause + "\", parameters={" + params + "}");
971972

972973
if (traceOn) {
973974
List<String> values = Collections.list(request.getHeaderNames());

spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerExceptionResolver.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,17 @@ public void setMappedHandlerClasses(Class<?>... mappedHandlerClasses) {
100100
/**
101101
* Set the log category for warn logging. The name will be passed to the underlying logger
102102
* implementation through Commons Logging, getting interpreted as a log category according
103-
* to the logger's configuration. If {@code null} is passed, warn logging is turned off.
104-
* <p>By default there is no warn logging although sub-classes like
103+
* to the logger's configuration. If {@code null} or empty String is passed, warn logging
104+
* is turned off.
105+
* <p>By default there is no warn logging although subclasses like
105106
* {@link org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver}
106107
* can change that default. Specify this setting to activate warn logging into a specific
107108
* category. Alternatively, override the {@link #logException} method for custom logging.
108109
* @see org.apache.commons.logging.LogFactory#getLog(String)
109110
* @see java.util.logging.Logger#getLogger(String)
110111
*/
111112
public void setWarnLogCategory(String loggerName) {
112-
this.warnLogger = (!StringUtils.isEmpty(loggerName) ? LogFactory.getLog(loggerName) : null);
113+
this.warnLogger = (StringUtils.hasLength(loggerName) ? LogFactory.getLog(loggerName) : null);
113114
}
114115

115116
/**

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -578,7 +578,7 @@ private static String getClassMapping(Class<?> controllerType) {
578578
return "/";
579579
}
580580
String[] paths = mapping.path();
581-
if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
581+
if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) {
582582
return "/";
583583
}
584584
if (paths.length > 1 && logger.isTraceEnabled()) {
@@ -594,7 +594,7 @@ private static String getMethodMapping(Method method) {
594594
throw new IllegalArgumentException("No @RequestMapping on: " + method.toGenericString());
595595
}
596596
String[] paths = requestMapping.path();
597-
if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
597+
if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) {
598598
return "/";
599599
}
600600
if (paths.length > 1 && logger.isTraceEnabled()) {

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -125,7 +125,7 @@ public void contributeMethodArgument(MethodParameter parameter, Object value,
125125
}
126126

127127
PathVariable ann = parameter.getParameterAnnotation(PathVariable.class);
128-
String name = (ann != null && !StringUtils.isEmpty(ann.value()) ? ann.value() : parameter.getParameterName());
128+
String name = (ann != null && StringUtils.hasLength(ann.value()) ? ann.value() : parameter.getParameterName());
129129
String formatted = formatUriValue(conversionService, new TypeDescriptor(parameter.nestedIfOptional()), value);
130130
uriVariables.put(name, formatted);
131131
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -168,7 +168,7 @@ protected Resource resolveResourceInternal(@Nullable HttpServletRequest request,
168168
}
169169

170170
String candidateVersion = versionStrategy.extractVersion(requestPath);
171-
if (StringUtils.isEmpty(candidateVersion)) {
171+
if (!StringUtils.hasLength(candidateVersion)) {
172172
return null;
173173
}
174174

spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -206,7 +206,7 @@ public String removePathExtension() {
206206
String extension = null;
207207
if (this.originalPath != null) {
208208
extension = UriUtils.extractFileExtension(this.originalPath);
209-
if (!StringUtils.isEmpty(extension)) {
209+
if (StringUtils.hasLength(extension)) {
210210
int end = this.originalPath.length() - (extension.length() + 1);
211211
replacePath(this.originalPath.substring(0, end));
212212
}

spring-webmvc/src/main/java/org/springframework/web/servlet/view/RedirectView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ protected boolean isRemoteHost(String targetUrl) {
650650
return false;
651651
}
652652
String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost();
653-
if (StringUtils.isEmpty(targetHost)) {
653+
if (!StringUtils.hasLength(targetHost)) {
654654
return false;
655655
}
656656
for (String host : getHosts()) {

spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ protected final SubProtocolHandler findProtocolHandler(WebSocketSession session)
429429
}
430430

431431
SubProtocolHandler handler;
432-
if (!StringUtils.isEmpty(protocol)) {
432+
if (StringUtils.hasLength(protocol)) {
433433
handler = this.protocolHandlerLookup.get(protocol);
434434
if (handler == null) {
435435
throw new IllegalStateException(

0 commit comments

Comments
 (0)