-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Core: Fix equality in StructLikeMap #9236
Core: Fix equality in StructLikeMap #9236
Conversation
@@ -146,25 +145,19 @@ public R getValue() { | |||
|
|||
@Override | |||
public int hashCode() { | |||
int hashCode = getKey().hashCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was also throwing NPE cause key could be null. Not anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, getKey().hashCode()
meant we used the hash of the actual element, not the wrapper.
return false; | ||
} else { | ||
StructLikeEntry that = (StructLikeEntry<R>) o; | ||
return Objects.equals(getKey(), that.getKey()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used getKey()
which unwrapped the object and we were loosing proper equality.
@@ -147,4 +149,32 @@ public void testKeysWithNulls() { | |||
|
|||
assertThat(map.remove(record3)).isEqualTo("aaa"); | |||
} | |||
|
|||
@Test | |||
public void testEqualsAndHashCode() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do a quick addition of a test for empty map equality? I am pretty sure that is fine but just to be complete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more nit about empty map comparison tests but this looks good to me
Thanks, @RussellSpitzer! |
This PR fixes equality in
StructLikeMap
. See tests for use cases that previously failed.