Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in Collections by

Clojure 1.12.7, JDK 21 (regression from 1.11.4; same on master).

Calling .stream, .parallelStream, or .spliterator on a subvec of vector-of throws ClassCastException.

Expected: return a stream or spliterator over the subvec elements, as in Clojure 1.11.4 and on a regular vector's subvec.

(def pv (subvec (vector-of :long 1 2 3) 0 2))
(.count (.stream pv))
;; Actual: ClassCastException: class clojure.core.Vec cannot be cast to class clojure.lang.APersistentVector
;; Expected: 2

(.spliterator pv)
;; Actual: ClassCastException
;; Expected: a Spliterator over [1 2]

Cause: SubVector.spliterator (added in CLJ-2791) casts the backing vector v to APersistentVector without an instanceof check, which fails for clojure.core.Vec (and any other IPersistentVector that doesn't extend APersistentVector). SubVector.iterator right above it checks v instanceof APersistentVector and falls back to super.iterator(); doing the same with super.spliterator() fixes this.

This bug was found while following up on the bugs reported at https://s.conao3.com/blog/2026/e4f733

Please log in or register to answer this question.

...