Skip to content

Commit 763d18c

Browse files
committed
Polish defaultElementEquals
See gh-16671
1 parent a89e6ff commit 763d18c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/source/ConfigurationPropertyName.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,17 @@ else if (ch1 != ch2) {
360360
i2++;
361361
}
362362
}
363-
while (i2 < l2) {
364-
char ch2 = Character.toLowerCase(e2.charAt(i, i2++));
365-
if (indexed2 || ElementsParser.isAlphaNumeric(ch2)) {
363+
if (i2 < l2) {
364+
if (indexed2) {
366365
return false;
367366
}
367+
do {
368+
char ch2 = Character.toLowerCase(e2.charAt(i, i2++));
369+
if (ElementsParser.isAlphaNumeric(ch2)) {
370+
return false;
371+
}
372+
}
373+
while (i2 < l2);
368374
}
369375
return true;
370376
}
@@ -399,7 +405,8 @@ else if (ch1 != ch2) {
399405
return false;
400406
}
401407
do {
402-
if (e2.charAt(i, i2++) != '-') {
408+
char ch2 = e2.charAt(i, i2++);
409+
if (ch2 != '-') {
403410
return false;
404411
}
405412
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/ConfigurationPropertyNameTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ public void equalsWhenNameStartsTheSameUsingDashedCompare() {
632632
ConfigurationPropertyName n2 = ConfigurationPropertyName
633633
.of("management.metrics.web.server.auto-time-requests");
634634
assertThat(n1).isNotEqualTo(n2);
635+
assertThat(n2).isNotEqualTo(n1);
635636
}
636637

637638
@Test

0 commit comments

Comments
 (0)