Ensure ClassPathResources with same path have same hash code
This commit aligns the hashCode() implementation in ClassPathResource with the recent change to the logic in equals(). See gh-29263
This commit is contained in:
parent
1082119c50
commit
8869ca27b1
|
|
@ -286,7 +286,7 @@ public class ClassPathResource extends AbstractFileResolvingResource {
|
|||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.path.hashCode();
|
||||
return this.absolutePath.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,6 +90,14 @@ class ClassPathResourceTests {
|
|||
assertThat(resource2).isEqualTo(resource1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourcesWithEquivalentAbsolutePathsHaveSameHashCode() {
|
||||
ClassPathResource resource1 = new ClassPathResource("Resource.class", getClass());
|
||||
ClassPathResource resource2 = new ClassPathResource("org/springframework/core/io/Resource.class", getClass().getClassLoader());
|
||||
assertThat(resource1.getPath()).isEqualTo(resource2.getPath());
|
||||
assertThat(resource1).hasSameHashCodeAs(resource2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourcesWithEquivalentAbsolutePathsFromDifferentClassLoadersAreNotEqual() {
|
||||
class SimpleThrowawayClassLoader extends OverridingClassLoader {
|
||||
|
|
|
|||
Loading…
Reference in New Issue