From 763d18ca68ddb7846d866ad6dda2f1fbe0e4a087 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sat, 1 Jun 2019 13:32:22 -0700 Subject: [PATCH] Polish defaultElementEquals See gh-16671 --- .../source/ConfigurationPropertyName.java | 15 +++++++++++---- .../source/ConfigurationPropertyNameTests.java | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) 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 bcc4038c2e4..7f6e85ea0b2 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 @@ -360,11 +360,17 @@ public final class ConfigurationPropertyName i2++; } } - while (i2 < l2) { - char ch2 = Character.toLowerCase(e2.charAt(i, i2++)); - if (indexed2 || ElementsParser.isAlphaNumeric(ch2)) { + if (i2 < l2) { + if (indexed2) { return false; } + do { + char ch2 = Character.toLowerCase(e2.charAt(i, i2++)); + if (ElementsParser.isAlphaNumeric(ch2)) { + return false; + } + } + while (i2 < l2); } return true; } @@ -399,7 +405,8 @@ public final class ConfigurationPropertyName return false; } do { - if (e2.charAt(i, i2++) != '-') { + char ch2 = e2.charAt(i, i2++); + if (ch2 != '-') { return false; } } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java index 942c99d589a..a6a8250a8bc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java @@ -632,6 +632,7 @@ public class ConfigurationPropertyNameTests { ConfigurationPropertyName n2 = ConfigurationPropertyName .of("management.metrics.web.server.auto-time-requests"); assertThat(n1).isNotEqualTo(n2); + assertThat(n2).isNotEqualTo(n1); } @Test