Skip to content

Commit 46f3534

Browse files
committed
Merge pull request #21394 from dreis2211
* pr/21394: Polish "Calculate hashCode only once in ConfigurationPropertyName" Calculate hashCode only once in ConfigurationPropertyName Closes gh-21394
2 parents df25603 + dd05307 commit 46f3534

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ public int hashCode() {
444444
}
445445
hashCode = 31 * hashCode + elementHashCode;
446446
}
447+
this.hashCode = hashCode;
447448
}
448449
return hashCode;
449450
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,4 +619,11 @@ void isValidWhenNotValidShouldReturnFalse() {
619619
assertThat(ConfigurationPropertyName.isValid("foo!bar")).isFalse();
620620
}
621621

622+
@Test
623+
void hashCodeIsStored() {
624+
ConfigurationPropertyName name = ConfigurationPropertyName.of("hash.code");
625+
int hashCode = name.hashCode();
626+
assertThat(name).hasFieldOrPropertyWithValue("hashCode", hashCode);
627+
}
628+
622629
}

0 commit comments

Comments
 (0)