From 5cb07e292d585541f04ce0aa8681703c4c695be1 Mon Sep 17 00:00:00 2001 From: "Santhoshkumar. P" Date: Thu, 1 Oct 2020 08:21:49 +0530 Subject: [PATCH] Polish empty string checks See gh-23550 --- .../boot/autoconfigure/amqp/RabbitProperties.java | 2 +- .../boot/cli/command/shell/CommandCompleter.java | 3 ++- .../ConfigurationMetadataAnnotationProcessor.java | 2 +- .../configurationprocessor/MetadataGenerationEnvironment.java | 4 ++-- .../boot/configurationprocessor/TypeUtils.java | 2 +- .../metadata/ConfigurationMetadata.java | 2 +- .../org/springframework/boot/loader/PropertiesLauncher.java | 4 ++-- .../java/org/springframework/boot/loader/jar/JarFile.java | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 1bbc401fd4..9515f23fae 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -290,7 +290,7 @@ public class RabbitProperties { } public void setVirtualHost(String virtualHost) { - this.virtualHost = "".equals(virtualHost) ? "/" : virtualHost; + this.virtualHost = StringUtils.hasLength(virtualHost) ? virtualHost : "/"; } public AddressShuffleMode getAddressShuffleMode() { diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/CommandCompleter.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/CommandCompleter.java index cc25a074bf..2e4e73f304 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/CommandCompleter.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/shell/CommandCompleter.java @@ -33,6 +33,7 @@ import jline.console.completer.StringsCompleter; import org.springframework.boot.cli.command.Command; import org.springframework.boot.cli.command.options.OptionHelp; import org.springframework.boot.cli.util.Log; +import org.springframework.util.StringUtils; /** * JLine {@link Completer} for Spring Boot {@link Command}s. @@ -74,7 +75,7 @@ public class CommandCompleter extends StringsCompleter { int completionIndex = super.complete(buffer, cursor, candidates); int spaceIndex = buffer.indexOf(' '); String commandName = ((spaceIndex != -1) ? buffer.substring(0, spaceIndex) : ""); - if (!"".equals(commandName.trim())) { + if (StringUtils.hasText(commandName)) { for (Command command : this.commands) { if (command.getName().equals(commandName)) { if (cursor == buffer.length() && buffer.endsWith(" ")) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java index ca6e9dff37..b97f9b3669 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessor.java @@ -298,7 +298,7 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor private void processEndpoint(AnnotationMirror annotation, TypeElement element) { Map elementValues = this.metadataEnv.getAnnotationElementValues(annotation); String endpointId = (String) elementValues.get("id"); - if (endpointId == null || "".equals(endpointId)) { + if (endpointId == null || endpointId.isEmpty()) { return; // Can't process that endpoint } String endpointKey = ItemMetadata.newItemMetadataPrefix("management.endpoint.", endpointId); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataGenerationEnvironment.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataGenerationEnvironment.java index 0e0682abfe..9bd98bc226 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataGenerationEnvironment.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/MetadataGenerationEnvironment.java @@ -180,8 +180,8 @@ class MetadataGenerationEnvironment { reason = (String) elementValues.get("reason"); replacement = (String) elementValues.get("replacement"); } - reason = "".equals(reason) ? null : reason; - replacement = "".equals(replacement) ? null : replacement; + reason = (reason == null || reason.isEmpty()) ? null : reason; + replacement = (replacement == null || replacement.isEmpty()) ? null : replacement; return new ItemDeprecation(reason, replacement); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java index 844c5c460a..3e2810e318 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/TypeUtils.java @@ -180,7 +180,7 @@ class TypeUtils { if (javadoc != null) { javadoc = NEW_LINE_PATTERN.matcher(javadoc).replaceAll("").trim(); } - return "".equals(javadoc) ? null : javadoc; + return (javadoc == null || javadoc.isEmpty()) ? null : javadoc; } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java index 048d4e0fb0..90a6f5e844 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/metadata/ConfigurationMetadata.java @@ -171,7 +171,7 @@ public class ConfigurationMetadata { public static String nestedPrefix(String prefix, String name) { String nestedPrefix = (prefix != null) ? prefix : ""; String dashedName = toDashedCase(name); - nestedPrefix += "".equals(nestedPrefix) ? dashedName : "." + dashedName; + nestedPrefix += (nestedPrefix == null || nestedPrefix.isEmpty()) ? dashedName : "." + dashedName; return nestedPrefix; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java index e7cfc3b10b..a84c01139e 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/PropertiesLauncher.java @@ -316,7 +316,7 @@ public class PropertiesLauncher extends Launcher { for (String path : commaSeparatedPaths.split(",")) { path = cleanupPath(path); // "" means the user wants root of archive but not current directory - path = "".equals(path) ? "/" : path; + path = (path == null || path.isEmpty()) ? "/" : path; paths.add(path); } if (paths.isEmpty()) { @@ -631,7 +631,7 @@ public class PropertiesLauncher extends Launcher { } EntryFilter filter = new PrefixMatchingArchiveFilter(root); List archives = asList(parent.getNestedArchives(null, filter)); - if (("".equals(root) || ".".equals(root)) && !path.endsWith(".jar") + if ((root == null || root.isEmpty() || ".".equals(root)) && !path.endsWith(".jar") && parent != PropertiesLauncher.this.parent) { // You can't find the root with an entry filter so it has to be added // explicitly. But don't add the root of the parent archive. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java index 68bde6d72c..acef1612d8 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java @@ -413,7 +413,7 @@ public class JarFile extends AbstractJarFile implements Iterable