Clojure

get/= on sorted collections when types don't match result in a ClassCastException

Details

  • Type: Defect Defect
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: Release 1.5, Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test

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)

Activity

Hide
OHTA Shogo added a comment -

Umm, my brain was not working right.
Util.compare() should raise an Exception when the arguments' type are different.

Show
OHTA Shogo added a comment - Umm, my brain was not working right. Util.compare() should raise an Exception when the arguments' type are different.
Hide
OHTA Shogo added a comment -

PersistentVector also has the same problem.

user=> (compare [1] [:a])
java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.Number

The cause of this problem is that Util.compare() casts the second argument
to Number without checking its type when the first argument is a Number.

Show
OHTA Shogo added a comment - PersistentVector also has the same problem. user=> (compare [1] [:a]) java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.lang.Number The cause of this problem is that Util.compare() casts the second argument to Number without checking its type when the first argument is a Number.

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated: