From 4cc598ac5e07e72785c82d30b1d5a358d6bc5a2b Mon Sep 17 00:00:00 2001 From: Johnny Lim Date: Tue, 19 Dec 2017 00:22:35 +0900 Subject: [PATCH] Replace contains() with indexOf() Closes gh-11373 --- .../org/springframework/boot/actuate/audit/AuditEvent.java | 4 ++-- .../org/springframework/boot/actuate/endpoint/web/Link.java | 1 - .../boot/autoconfigure/web/ServerProperties.java | 5 +++-- .../org/springframework/boot/loader/PropertiesLauncher.java | 4 ++-- .../boot/web/servlet/server/DocumentRoot.java | 5 +++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java index 0c25cfce38..a6e287919a 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java @@ -95,8 +95,8 @@ public class AuditEvent implements Serializable { private static Map convert(String[] data) { Map result = new HashMap<>(); for (String entry : data) { - if (entry.contains("=")) { - int index = entry.indexOf("="); + int index = entry.indexOf("="); + if (index != -1) { result.put(entry.substring(0, index), entry.substring(index + 1)); } else { diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/Link.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/Link.java index 681c4b8e7c..5365895e05 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/Link.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/Link.java @@ -39,7 +39,6 @@ public class Link { public Link(String href) { this.href = href; this.templated = href.contains("{"); - } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 14eee32e5f..d50b80e992 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -303,8 +303,9 @@ public class ServerProperties { public String getServletPrefix() { String result = this.path; - if (result.contains("*")) { - result = result.substring(0, result.indexOf("*")); + int index = result.indexOf("*"); + if (index != -1) { + result = result.substring(0, index); } if (result.endsWith("/")) { result = result.substring(0, result.length() - 1); 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 7b49a0ac13..edb41259b6 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 @@ -498,8 +498,8 @@ public class PropertiesLauncher extends Launcher { // If home dir is same as parent archive, no need to add it twice. return null; } - if (root.contains("!")) { - int index = root.indexOf("!"); + int index = root.indexOf("!"); + if (index != -1) { File file = new File(this.home, root.substring(0, index)); if (root.startsWith("jar:file:")) { file = new File(root.substring("jar:file:".length(), index)); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DocumentRoot.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DocumentRoot.java index fc1f21f7f4..b6cacc03b5 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DocumentRoot.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/DocumentRoot.java @@ -109,8 +109,9 @@ class DocumentRoot { else { path = location.toURI().getPath(); } - if (path.contains("!/")) { - path = path.substring(0, path.indexOf("!/")); + int index = path.indexOf("!/"); + if (index != -1) { + path = path.substring(0, index); } return new File(path); }