-
Notifications
You must be signed in to change notification settings - Fork 153
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
Fix HashMap put/remove returned value for empty key after clear. #237
Conversation
@@ -131,8 +131,8 @@ public VType put(KType key, VType value) { | |||
|
|||
final int mask = this.mask; | |||
if (Intrinsics.<KType> isEmpty(key)) { | |||
VType previousValue = hasEmptyKey ? Intrinsics.<VType> cast(values[mask + 1]) : Intrinsics.<VType> empty(); |
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.
Bug fix
@@ -237,6 +237,9 @@ public VType addTo(KType key, VType incrementValue) | |||
public VType remove(KType key) { | |||
final int mask = this.mask; | |||
if (Intrinsics.<KType> isEmpty(key)) { | |||
if (!hasEmptyKey) { |
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.
Bug fix
try { | ||
set.indexGet(set.indexOf(key2)); | ||
fail(); |
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 fail would be caught anyway. Fix it.
@@ -393,16 +421,15 @@ public void testNullKey() | |||
} | |||
/*! #end !*/ | |||
|
|||
/*! #if ($TemplateOptions.KTypeGeneric) !*/ |
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.
Make this randomized test run for primitive keys/values.
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.
Oh boy... What shocks me more is not that you've found a bug - these are always there - but that it's been 14 years (!)...
Thank you!
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.
Thanks, @bruno-roustant ! I'll do a few other cleanups and I think this warrants a release!
While finishing to test the small fork of HPPC in Lucene, I discovered a small bug in HashMap put and remove, in the returned value, after clear was called on the map. This is a edge case clearly, but I found a bug after 14 years of HPPC :)
This PR also adds more tests, making the randomized test against JDK HashMap run even for primitive keys/values (that revealed the small bug).