Skip to content

ClassPathResources with same absolute path and same ClassLoader should be equal #29263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sbrannen opened this issue Oct 5, 2022 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@sbrannen
Copy link
Member

sbrannen commented Oct 5, 2022

Currently, if two ClassPathResource instances are constructed differently (one with an absolute path and one with a path relative to a Class) but have the same absolute path and the same ClassLoader, they are effectively equal, but ClassPathResource#equals returns false.

For example, the following test fails.

@Test
void resourcesWithEquivalentAbsolutePathsAreEqual() {
	Resource resource1 = new ClassPathResource("Resource.class", getClass());
	Resource resource2 = new ClassPathResource("org/springframework/core/io/Resource.class", getClass().getClassLoader());
	assertThat(resource2).isEqualTo(resource1);
}
@sbrannen sbrannen added type: bug A general bug in: core Issues in core modules (aop, beans, core, context, expression) labels Oct 5, 2022
@sbrannen sbrannen added this to the 6.0.0-RC1 milestone Oct 5, 2022
@sbrannen sbrannen self-assigned this Oct 5, 2022
sbrannen added a commit to sbrannen/spring-framework that referenced this issue Oct 5, 2022
This commit aligns the hashCode() implementation in ClassPathResource
with the recent change to the logic in equals().

See spring-projectsgh-29263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant