Commit c9f6a126 authored by dreis2211's avatar dreis2211 Committed by Stephane Nicoll

Calculate hashCode only once in ConfigurationPropertyName

See gh-21394
parent df25603b
...@@ -444,6 +444,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration ...@@ -444,6 +444,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
} }
hashCode = 31 * hashCode + elementHashCode; hashCode = 31 * hashCode + elementHashCode;
} }
this.hashCode = hashCode;
} }
return hashCode; return hashCode;
} }
......
...@@ -24,6 +24,7 @@ import java.util.stream.Collectors; ...@@ -24,6 +24,7 @@ import java.util.stream.Collectors;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.context.properties.source.ConfigurationPropertyName.Form; 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.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
...@@ -619,4 +620,12 @@ class ConfigurationPropertyNameTests { ...@@ -619,4 +620,12 @@ class ConfigurationPropertyNameTests {
assertThat(ConfigurationPropertyName.isValid("foo!bar")).isFalse(); assertThat(ConfigurationPropertyName.isValid("foo!bar")).isFalse();
} }
@Test
void hashCodeIsOnlyCalculatedOnce() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("hash.code");
int hashCode = name.hashCode();
int hashCodeField = (int) ReflectionTestUtils.getField(name, "hashCode");
assertThat(hashCodeField).isEqualTo(hashCode);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment