From c9f6a126b7a474951c3d52f5ced022a519c27e5f Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Mon, 11 May 2020 22:13:53 +0200 Subject: [PATCH 1/2] Calculate hashCode only once in ConfigurationPropertyName See gh-21394 --- .../properties/source/ConfigurationPropertyName.java | 1 + .../source/ConfigurationPropertyNameTests.java | 9 +++++++++ 2 files changed, 10 insertions(+) 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 894439c0a3..fa0b7d866a 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 @@ -444,6 +444,7 @@ public final class ConfigurationPropertyName implements Comparable Date: Tue, 12 May 2020 10:05:32 +0200 Subject: [PATCH 2/2] Polish "Calculate hashCode only once in ConfigurationPropertyName" See gh-21394 --- .../properties/source/ConfigurationPropertyNameTests.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 136a144063..9887a67bcc 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 @@ -24,7 +24,6 @@ import java.util.stream.Collectors; import org.junit.jupiter.api.Test; import org.springframework.boot.context.properties.source.ConfigurationPropertyName.Form; -import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -621,11 +620,10 @@ class ConfigurationPropertyNameTests { } @Test - void hashCodeIsOnlyCalculatedOnce() { + void hashCodeIsStored() { ConfigurationPropertyName name = ConfigurationPropertyName.of("hash.code"); int hashCode = name.hashCode(); - int hashCodeField = (int) ReflectionTestUtils.getField(name, "hashCode"); - assertThat(hashCodeField).isEqualTo(hashCode); + assertThat(name).hasFieldOrPropertyWithValue("hashCode", hashCode); } }