Clojure

Inconsistent hash with java collections

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Environment:
    1.6.0 master
  • Patch:
    Code and Test
  • Approval:
    Triaged

Description

c.c/hash always use hashCode for java collections, which is incompatible when comparing with Clojure collections, which use Murmur3.

user=> (== (hash (java.util.ArrayList. [1 2 3])) (hash [1 2 3]))
false
user=> (= (java.util.ArrayList. [1 2 3]) [1 2 3])
true

One way to fix it is to add a special case in Util/hasheq for java.util.Collections, as it is now for Strings.

Link to a discussion of this topic in the Clojure group: https://groups.google.com/forum/#!topic/clojure/dQhdwZsyIEw

Activity

Jozef Wagner made changes -
Field Original Value New Value
Attachment clj-1372.diff [ 12864 ]
Andy Fingerhut made changes -
Attachment clj-1372-2.diff [ 12866 ]
Andy Fingerhut made changes -
Patch Code and Test [ 10002 ]
Alex Miller made changes -
Labels collections
Andy Fingerhut made changes -
Affects Version/s Release 1.6 [ 10157 ]
Andy Fingerhut made changes -
Description c.c/hash always use hashCode for java collections, which is incompatible when comparing with Clojure collections, which use Murmur3.

{code}
user=> (== (hash (java.util.ArrayList. [1 2 3])) (hash [1 2 3]))
false
user=> (= (java.util.ArrayList. [1 2 3]) [1 2 3])
true
{code}

One way to fix it is to add a special case in Util/hasheq for java.util.Collections, as it is now for Strings.
c.c/hash always use hashCode for java collections, which is incompatible when comparing with Clojure collections, which use Murmur3.

{code}
user=> (== (hash (java.util.ArrayList. [1 2 3])) (hash [1 2 3]))
false
user=> (= (java.util.ArrayList. [1 2 3]) [1 2 3])
true
{code}

One way to fix it is to add a special case in Util/hasheq for java.util.Collections, as it is now for Strings.

Link to a discussion of this topic in the Clojure group: https://groups.google.com/forum/#!topic/clojure/dQhdwZsyIEw
John Hume made changes -
Labels collections collections interop
Michał Marczyk made changes -
Michał Marczyk made changes -
Michał Marczyk made changes -
Michał Marczyk made changes -
Alex Miller made changes -
Approval Triaged [ 10120 ]

People

Vote (6)
Watch (8)

Dates

  • Created:
    Updated: