Clojure

= on sorted collections with different key types incorrectly throws

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: Release 1.5, Release 1.6
  • Fix Version/s: Release 1.9
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

Comparing a sorted-set with numbers to a set with keywords is not symmetric:

user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword  clojure.lang.Keyword.compareTo (Keyword.java:109)

The latter case should return false instead of throwing.

Cause: APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check.

Proposed: It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

See also: CLJ-1983 (downstream example with clojure.data/diff)

Patch: 0001-CLJ-1242-equals-doesn-t-throw-on-sorted-collections.patch

Screened by: Alex Miller

Activity

Alex Miller made changes -
Field Original Value New Value
Priority Minor [ 4 ] Major [ 3 ]
Approval Triaged [ 10120 ]
Stuart Halloway made changes -
Priority Major [ 3 ] Minor [ 4 ]
Alex Miller made changes -
Summary get/= on sorted collections when types don't match result in a ClassCastException = on sorted collections with different key types incorrectly throws
Labels collections
Description user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)

but

user=> (= (sorted-set 1) :a)
false

also

user=> (get (sorted-set 1) :a 2)
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check. It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.
Alex Miller made changes -
Description Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check. It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.
Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check. It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

*See also:* CLJ-1983 (downstream example with clojure.data/diff)
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Alex Miller made changes -
Status Open [ 1 ] Closed [ 6 ]
Resolution Duplicate [ 3 ]
Alex Miller made changes -
Resolution Duplicate [ 3 ]
Status Closed [ 6 ] Reopened [ 4 ]
Rich Hickey made changes -
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Alex Miller made changes -
Fix Version/s Release 1.9 [ 10750 ]
Alex Miller made changes -
Description Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check. It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

*See also:* CLJ-1983 (downstream example with clojure.data/diff)
Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check.

*Proposed:* It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

*See also:* CLJ-1983 (downstream example with clojure.data/diff)
Approval Vetted [ 10003 ] Incomplete [ 10006 ]
Nicola Mometto made changes -
Attachment 0001-CLJ-1242-equals-doesn-t-throw-on-sorted-collections.patch [ 16016 ]
Description Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check.

*Proposed:* It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

*See also:* CLJ-1983 (downstream example with clojure.data/diff)
Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check.

*Proposed:* It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

*See also:* CLJ-1983 (downstream example with clojure.data/diff)

*Patch:* 0001-CLJ-1242-equals-doesn-t-throw-on-sorted-collections.patch
Alex Miller made changes -
Approval Incomplete [ 10006 ] Vetted [ 10003 ]
Alex Miller made changes -
Description Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check.

*Proposed:* It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

*See also:* CLJ-1983 (downstream example with clojure.data/diff)

*Patch:* 0001-CLJ-1242-equals-doesn-t-throw-on-sorted-collections.patch
Comparing a sorted-set with numbers to a set with keywords is not symmetric:

{code}
user=> (= #{:a} (sorted-set 1))
false
user=> (= (sorted-set 1) #{:a})
ClassCastException java.lang.Long cannot be cast to clojure.lang.Keyword clojure.lang.Keyword.compareTo (Keyword.java:109)
{code}

The latter case should return false instead of throwing.

*Cause:* APersistentMap.equiv() and APersistentSet.equiv() do not expect this exception be thrown from the containsKey()/contains() check.

*Proposed:* It would probably be best for PersistentTreeMap and PersistentTreeMap to implement equiv() and handle that possibility appropriately. Should also consider similar changes in equals() if necessary.

*See also:* CLJ-1983 (downstream example with clojure.data/diff)

*Patch:* 0001-CLJ-1242-equals-doesn-t-throw-on-sorted-collections.patch

*Screened by:* Alex Miller
Approval Vetted [ 10003 ] Screened [ 10004 ]
Nicola Mometto made changes -
Attachment 0001-CLJ-1242-equals-doesn-t-throw-on-sorted-collections.patch [ 16016 ]
Nicola Mometto made changes -
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Status Reopened [ 4 ] Closed [ 6 ]
Resolution Completed [ 1 ]

People

Vote (7)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: