Skip to content

Commit 574e470

Browse files
authored
Merge pull request #75 from NoahTheDuke/nb/fix-set-npe
Fast-follow to #74 Fix NPE in ordered sets
2 parents b4277db + 05952c3 commit 574e470

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/flatland/ordered/set.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
(toString [this]
5757
(str "#{" (clojure.string/join " " (map str this)) "}"))
5858
(hashCode [this]
59-
(reduce + (keep #(when % (.hashCode ^Object %)) (.seq this))))
59+
(reduce + (keep #(when (some? %) (.hashCode ^Object %)) (.seq this))))
6060
(equals [this other]
6161
(or (identical? this other)
6262
(and (instance? Set other)

test/flatland/ordered/set_test.clj

+5
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@
165165
(is (= (.hashCode (ordered-set nil)) (.hashCode (hash-set nil))))
166166
(is (= (.hashCode (ordered-set nil :a {:b nil})) (.hashCode (hash-set nil :a {:b nil}))))))
167167

168+
(deftest nil-and-false-hashes
169+
(is (not= (.hashCode (ordered-set nil)) (.hashCode (hash-set false))))
170+
(is (not= (.hashCode (ordered-set false)) (.hashCode (hash-set nil))))
171+
(is (= (.hashCode (ordered-set false nil)) (.hashCode (hash-set nil false)))))
172+
168173
(deftest nil-hash-code-npe
169174
;; No assertions here; just check that it doesn't NPE
170175
;; See: https://github.com/amalloy/ordered/issues/27

0 commit comments

Comments
 (0)