Calculate hashCode only once in ConfigurationPropertyName
See gh-21394
This commit is contained in:
committed by
Stephane Nicoll
parent
df25603bc9
commit
c9f6a126b7
@@ -444,6 +444,7 @@ public final class ConfigurationPropertyName implements Comparable<Configuration
|
||||
}
|
||||
hashCode = 31 * hashCode + elementHashCode;
|
||||
}
|
||||
this.hashCode = hashCode;
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ 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;
|
||||
@@ -619,4 +620,12 @@ class ConfigurationPropertyNameTests {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user