Consistent use of StringUtils.hasLength(String) vs isEmpty(Object)

This commit is contained in:
Juergen Hoeller
2019-05-03 17:29:14 +02:00
parent 84266d71e9
commit a7949ac84a
18 changed files with 49 additions and 42 deletions

View File

@@ -963,11 +963,12 @@ public class DispatcherServlet extends FrameworkServlet {
params = (request.getParameterMap().isEmpty() ? "" : "masked");
}
String query = StringUtils.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString();
String queryString = request.getQueryString();
String queryClause = (StringUtils.hasLength(queryString) ? "?" + queryString : "");
String dispatchType = (!request.getDispatcherType().equals(DispatcherType.REQUEST) ?
"\"" + request.getDispatcherType().name() + "\" dispatch for " : "");
String message = (dispatchType + request.getMethod() + " \"" + getRequestUri(request) +
query + "\", parameters={" + params + "}");
queryClause + "\", parameters={" + params + "}");
if (traceOn) {
List<String> values = Collections.list(request.getHeaderNames());

View File

@@ -100,8 +100,9 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
/**
* Set the log category for warn logging. The name will be passed to the underlying logger
* implementation through Commons Logging, getting interpreted as a log category according
* to the logger's configuration. If {@code null} is passed, warn logging is turned off.
* <p>By default there is no warn logging although sub-classes like
* to the logger's configuration. If {@code null} or empty String is passed, warn logging
* is turned off.
* <p>By default there is no warn logging although subclasses like
* {@link org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver}
* can change that default. Specify this setting to activate warn logging into a specific
* category. Alternatively, override the {@link #logException} method for custom logging.
@@ -109,7 +110,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti
* @see java.util.logging.Logger#getLogger(String)
*/
public void setWarnLogCategory(String loggerName) {
this.warnLogger = (!StringUtils.isEmpty(loggerName) ? LogFactory.getLog(loggerName) : null);
this.warnLogger = (StringUtils.hasLength(loggerName) ? LogFactory.getLog(loggerName) : null);
}
/**

View File

@@ -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.
@@ -578,7 +578,7 @@ public class MvcUriComponentsBuilder {
return "/";
}
String[] paths = mapping.path();
if (ObjectUtils.isEmpty(paths) || StringUtils.isEmpty(paths[0])) {
if (ObjectUtils.isEmpty(paths) || !StringUtils.hasLength(paths[0])) {
return "/";
}
if (paths.length > 1 && logger.isTraceEnabled()) {
@@ -594,7 +594,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.isTraceEnabled()) {

View File

@@ -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);
}

View File

@@ -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)) {
return null;
}

View File

@@ -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.
@@ -206,7 +206,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));
}

View File

@@ -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()) {