Skip to content

Commit

Permalink
Harmonize equals/hashCode of OverrideMetadata to use class identity
Browse files Browse the repository at this point in the history
This commit harmonizes the equals/hashCode behavior of OverrideMetadata
to always take the implementation class as a factor for its identity.

This is important as two OverrideMetadata implementations could use
the same strategy and other settings while creating the override value
in a totally different way. This commit makes sure they are identified
as different.

Closes gh-33005
  • Loading branch information
snicoll committed Jun 11, 2024
1 parent 1be92f8 commit 2a68093
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public boolean equals(Object other) {
if (other == this) {
return true;
}
if (other == null || !getClass().isAssignableFrom(other.getClass())) {
if (other == null || other.getClass() != getClass()) {
return false;
}
OverrideMetadata that = (OverrideMetadata) other;
Expand All @@ -182,7 +182,7 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
int hash = Objects.hash(this.beanType.getType(), this.beanName, this.strategy);
int hash = Objects.hash(getClass().hashCode(), this.beanType.getType(), this.beanName, this.strategy);
return (this.beanName != null ? hash : hash +
Objects.hash(this.field.getName(), Arrays.hashCode(this.field.getAnnotations())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,6 @@ <T> T createSpy(String name, Object instance) {
return (T) mock(toSpy, settings);
}

@Override
public boolean equals(@Nullable Object other) {
if (other == this) {
return true;
}
// For SpyBean we want the class to be exactly the same.
if (other == null || other.getClass() != getClass()) {
return false;
}
return super.equals(other);
}

@Override
public int hashCode() {
return getClass().hashCode() * 29 + super.hashCode();
}

@Override
public String toString() {
return new ToStringCreator(this)
Expand Down

0 comments on commit 2a68093

Please sign in to comment.