clj-commons / potemkin

some ideas which are almost good
572 stars 53 forks source link

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

Closed dpsutton closed 7 years ago

dpsutton commented 7 years ago

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.

ztellman commented 7 years ago

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

dpsutton commented 7 years ago

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

dpsutton commented 7 years ago

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

ztellman commented 7 years ago

No test required, thanks for the report and fix.