<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged spliterator</title>
<link>https://ask.clojure.org/index.php/tag/spliterator</link>
<description>Powered by Question2Answer</description>
<item>
<title>Calling .stream or .spliterator on a subvec of vector-of throws ClassCastException (regression in 1.12)</title>
<link>https://ask.clojure.org/index.php/15309/calling-stream-spliterator-classcastexception-regression</link>
<description>&lt;p&gt;Clojure 1.12.7, JDK 21 (regression from 1.11.4; same on master).&lt;/p&gt;
&lt;p&gt;Calling &lt;code&gt;.stream&lt;/code&gt;, &lt;code&gt;.parallelStream&lt;/code&gt;, or &lt;code&gt;.spliterator&lt;/code&gt; on a &lt;code&gt;subvec&lt;/code&gt; of &lt;code&gt;vector-of&lt;/code&gt; throws &lt;code&gt;ClassCastException&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Expected: return a stream or spliterator over the subvec elements, as in Clojure 1.11.4 and on a regular vector&#039;s &lt;code&gt;subvec&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(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]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Cause: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/clojure-1.12.7/src/jvm/clojure/lang/APersistentVector.java#L641-L643&quot;&gt;SubVector.spliterator&lt;/a&gt; (added in &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2791&quot;&gt;CLJ-2791&lt;/a&gt;) casts the backing vector &lt;code&gt;v&lt;/code&gt; to &lt;code&gt;APersistentVector&lt;/code&gt; without an &lt;code&gt;instanceof&lt;/code&gt; check, which fails for &lt;code&gt;clojure.core.Vec&lt;/code&gt; (and any other &lt;code&gt;IPersistentVector&lt;/code&gt; that doesn&#039;t extend &lt;code&gt;APersistentVector&lt;/code&gt;). &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/clojure-1.12.7/src/jvm/clojure/lang/APersistentVector.java#L633-L638&quot;&gt;SubVector.iterator&lt;/a&gt; right above it checks &lt;code&gt;v instanceof APersistentVector&lt;/code&gt; and falls back to &lt;code&gt;super.iterator()&lt;/code&gt;; doing the same with &lt;code&gt;super.spliterator()&lt;/code&gt; fixes this.&lt;/p&gt;
&lt;p&gt;This bug was found while following up on the bugs reported at &lt;a rel=&quot;nofollow&quot; href=&quot;https://s.conao3.com/blog/2026/e4f733&quot;&gt;https://s.conao3.com/blog/2026/e4f733&lt;/a&gt;&lt;/p&gt;
</description>
<category>Collections</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15309/calling-stream-spliterator-classcastexception-regression</guid>
<pubDate>Thu, 03 Dec 2026 19:23:31 +0000</pubDate>
</item>
</channel>
</rss>