Skip to content

OverrideMetadata equals/hashCode should rely on getClass() #33005

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
snicoll opened this issue Jun 11, 2024 · 1 comment
Closed

OverrideMetadata equals/hashCode should rely on getClass() #33005

snicoll opened this issue Jun 11, 2024 · 1 comment
Assignees
Labels
type: task A general task
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Jun 11, 2024

equals and hashCode implementations in MockitoSpyBeanOverrideMetadata care about getClass() but shouldn't:

}
// For SpyBean we want the class to be exactly the same.
if (other == null || other.getClass() != getClass()) {
return false;
}

This looks like a copy/paste from the Spring Boot implementation that doesn't have the notion of BeanOverrideStrategy that is enough already to differentiate between those two.

@snicoll snicoll added the type: task A general task label Jun 11, 2024
@snicoll snicoll added this to the 6.2.0-M4 milestone Jun 11, 2024
@snicoll snicoll self-assigned this Jun 11, 2024
@snicoll
Copy link
Member Author

snicoll commented Jun 11, 2024

Looking a bit more after having removed that code, it turns out things are working but could stop if someone created an OverrideMetadata with the same settings in a different class. For instance something similar to TestBeanOverrideMetadata but with a completely different approach to how the override is created. While very unlikely, harmonizing equals/hashCode so that the OverrideMetadata implementation is part of the key sounds sensible.

@snicoll snicoll changed the title MockitoSpyBeanOverrideMetadata equals/hashCode should not care about getClass() OverrideMetadata equals/hashCode should rely on getClass() Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

1 participant