Skip to content
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

Fixes NPE in hashcode with empty keys (Issue 52) #53

Merged
merged 1 commit into from Jun 22, 2017

Conversation

dpsutton
Copy link
Contributor

Several alternatives were tried: if you put the whole unchecked-add if
an (if (and k v) (unchecked-add ...) 0) then you get a hashvalue of
0 when there is only one key and a missing value as the key isn't
hashed. If you (unchecked-add acc (bit-xor (.hashCode (or k 0)) ..
then you end up with reflection warnings.

(unchecked-add acc (bit-xor (.hashCode k) (.hashCode v))))
(fn [acc [k v]]
(unchecked-add acc (bit-xor
(if k (.hashCode k) 0)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, maybe (if (some? k) (.hashCode k) 0), since (not= 0 (.hashCode false))...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see what you mean. but its more relevant for a value rather than the key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and that's not gonna be a nitpick but we just won't hash false values with my code :)

@dpsutton dpsutton force-pushed the master branch 2 times, most recently from 195fadc to 4bca73a Compare June 21, 2017 05:32
@ztellman
Copy link
Collaborator

I'd prefer to use clojure.lang.Util/hash rather than the "some" check .

@dpsutton
Copy link
Contributor Author

ah. didn't know about that one. Worked like a charm. Updated @ztellman

@dpsutton
Copy link
Contributor Author

Also, can add a test if you would like but it's not particularly complicated. Up to you

@ztellman ztellman merged commit 0350aff into clj-commons:master Jun 22, 2017
@ztellman
Copy link
Collaborator

No test required, thanks for the report and fix.

tobias added a commit to immutant/immutant that referenced this pull request Jun 23, 2017
…ANT-633]

This just ports the fix from clj-commons/potemkin#53
to our vendored potemkin.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants