Skip to content

Commit b4277db

Browse files
authored
Merge pull request #74 from NoahTheDuke/nb/fix-set-npe
Fix NPE in ordered-set
2 parents 8cc133d + 6977ad7 commit b4277db

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/flatland/ordered/set.clj

Lines changed: 1 addition & 1 deletion
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 + (map #(.hashCode ^Object %) (.seq this))))
59+
(reduce + (keep #(when % (.hashCode ^Object %)) (.seq this))))
6060
(equals [this other]
6161
(or (identical? this other)
6262
(and (instance? Set other)

test/flatland/ordered/set_test.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,14 @@
160160
(is (= (hash m1) (hash m2)))
161161
(is (= (.hashCode m1) (.hashCode m2)))
162162
(is (= (hash (ordered-set)) (hash (hash-set))))
163-
(is (= (.hashCode (ordered-set)) (.hashCode (hash-set))))))
163+
(is (= (.hashCode (ordered-set)) (.hashCode (hash-set))))
164+
(is (= (hash (ordered-set nil)) (hash (hash-set nil))))
165+
(is (= (.hashCode (ordered-set nil)) (.hashCode (hash-set nil))))
166+
(is (= (.hashCode (ordered-set nil :a {:b nil})) (.hashCode (hash-set nil :a {:b nil}))))))
164167

165168
(deftest nil-hash-code-npe
166169
;; No assertions here; just check that it doesn't NPE
167170
;; See: https://github.com/amalloy/ordered/issues/27
168-
(are [contents] (.hashCode (ordered-set contents))
171+
(are [contents] (.hashCode (apply ordered-set contents))
169172
[nil]
170173
[nil :a]))

0 commit comments

Comments
 (0)