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 c0aa460d06..facf2a9539 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 @@ -397,7 +397,7 @@ public final class ConfigurationPropertyName boolean indexed2 = e2.getType(i).isIndexed(); while (i2 < l2) { char ch2 = e2.charAt(i, i2++); - if (indexed2 || ch2 == '-') { + if (indexed2 || 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 9c803fdb71..942c99d589 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 @@ -624,6 +624,16 @@ public class ConfigurationPropertyNameTests { assertThat(n1).isNotEqualTo(n2); } + @Test + public void equalsWhenNameStartsTheSameUsingDashedCompare() { + // gh-16855 + ConfigurationPropertyName n1 = ConfigurationPropertyName + .of("management.metrics.web.server.auto-time-request"); + ConfigurationPropertyName n2 = ConfigurationPropertyName + .of("management.metrics.web.server.auto-time-requests"); + assertThat(n1).isNotEqualTo(n2); + } + @Test public void isValidWhenValidShouldReturnTrue() { assertThat(ConfigurationPropertyName.isValid("")).isTrue();