diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizerFactory.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizerFactory.java index de8c55c9fc..39e1c04fca 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizerFactory.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizerFactory.java @@ -59,7 +59,7 @@ class WebDriverContextCustomizerFactory implements ContextCustomizerFactory { if (obj == this) { return true; } - if (obj == null || !obj.getClass().equals(getClass())) { + if (obj == null || obj.getClass() != getClass()) { return false; } return true; diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java index 68dcc2fe74..3279677dea 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/web/reactive/WebTestClientContextCustomizer.java @@ -74,7 +74,7 @@ class WebTestClientContextCustomizer implements ContextCustomizer { @Override public boolean equals(Object obj) { - return (obj != null && obj.getClass().equals(getClass())); + return (obj != null && obj.getClass() == getClass()); } /** diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java index 75d47cc57e..d828c2aacc 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/AsciiBytes.java @@ -211,7 +211,7 @@ final class AsciiBytes { if (this == obj) { return true; } - if (obj.getClass().equals(AsciiBytes.class)) { + if (obj.getClass() == AsciiBytes.class) { AsciiBytes other = (AsciiBytes) obj; if (this.length == other.length) { for (int i = 0; i < this.length; i++) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java index 7b8ac56812..c7a1cada67 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java @@ -355,7 +355,7 @@ public final class ConfigurationPropertyName if (obj == this) { return true; } - if (obj == null || !obj.getClass().equals(getClass())) { + if (obj == null || obj.getClass() != getClass()) { return false; } ConfigurationPropertyName other = (ConfigurationPropertyName) obj; @@ -410,8 +410,11 @@ public final class ConfigurationPropertyName private static boolean isIndexed(CharSequence element) { int length = element.length(); - return length > 2 && element.charAt(0) == '[' - && element.charAt(length - 1) == ']'; + return charAt(element, 0) == '[' && charAt(element, length - 1) == ']'; + } + + private static char charAt(CharSequence element, int index) { + return (index < element.length() ? element.charAt(index) : 0); } /** @@ -496,7 +499,7 @@ public final class ConfigurationPropertyName if (name.length() == 0) { return EMPTY; } - List elements = new ArrayList<>(10); + List elements = new ArrayList<>(); process(name, separator, (elementValue, start, end, indexed) -> { elementValue = elementValueProcessor.apply(elementValue); if (!isIndexed(elementValue)) { @@ -656,10 +659,16 @@ public final class ConfigurationPropertyName } public static boolean isValidElement(CharSequence elementValue) { - return getInvalidChars(elementValue).isEmpty(); + for (int i = 0; i < elementValue.length(); i++) { + char ch = elementValue.charAt(i); + if (!isValidChar(ch, i)) { + return false; + } + } + return true; } - private static List getInvalidChars(CharSequence elementValue) { + public static List getInvalidChars(CharSequence elementValue) { List chars = new ArrayList<>(); for (int i = 0; i < elementValue.length(); i++) { char ch = elementValue.charAt(i); @@ -671,12 +680,15 @@ public final class ConfigurationPropertyName } public static boolean isValidChar(char ch, int index) { - boolean isAlpha = ch >= 'a' && ch <= 'z'; - boolean isNumeric = ch >= '0' && ch <= '9'; - if (index == 0) { - return isAlpha; - } - return isAlpha || isNumeric || ch == '-'; + return isAlpha(ch) || (index != 0 && (isNumeric(ch) || ch == '-')); + } + + private static boolean isAlpha(char ch) { + return ch >= 'a' && ch <= 'z'; + } + + private static boolean isNumeric(char ch) { + return ch >= '0' && ch <= '9'; } }