<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions tagged nthnext</title>
<link>https://ask.clojure.org/index.php/tag/nthnext</link>
<description>Powered by Question2Answer</description>
<item>
<title>drop on a string seq or vector seq returns a broken seq when n is close to Integer/MAX_VALUE (regression in 1.12)</title>
<link>https://ask.clojure.org/index.php/15311/string-vector-returns-broken-integer-maxvalue-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;&lt;code&gt;drop&lt;/code&gt; (and &lt;code&gt;nthnext&lt;/code&gt;, &lt;code&gt;nthrest&lt;/code&gt;) on a non-initial string seq or vector seq overflows &lt;code&gt;int&lt;/code&gt; when &lt;code&gt;n&lt;/code&gt; is close to &lt;code&gt;Integer/MAX_VALUE&lt;/code&gt;, returning a broken seq at a negative index or throwing &lt;code&gt;IndexOutOfBoundsException&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Expected: &lt;code&gt;()&lt;/code&gt; (and &lt;code&gt;nil&lt;/code&gt; for &lt;code&gt;nthnext&lt;/code&gt;), matching Clojure 1.11.4 and the other &lt;code&gt;IDrop&lt;/code&gt; implementations (&lt;code&gt;PersistentVector&lt;/code&gt;, &lt;code&gt;PersistentArrayMap&lt;/code&gt;, &lt;code&gt;LongRange&lt;/code&gt;, &lt;code&gt;Repeat&lt;/code&gt;).&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(count (drop Integer/MAX_VALUE (next (seq &quot;abc&quot;))))
;; Actual: -2147483645
;; Expected: 0

(drop Integer/MAX_VALUE (next (seq &quot;abc&quot;)))
;; Actual: printing throws StringIndexOutOfBoundsException: Index -2147483648
;; Expected: ()

(drop Integer/MAX_VALUE (next (seq [1 2 3])))
;; Actual: printing throws ArrayIndexOutOfBoundsException: Index -2147483648
;; Expected: ()

(drop (- Integer/MAX_VALUE 10) (nthnext (seq (vec (range 40))) 32))
;; Actual: IndexOutOfBoundsException
;; Expected: ()
&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/StringSeq.java#L61-L68&quot;&gt;StringSeq.drop&lt;/a&gt; and &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/clojure/clojure/blob/clojure-1.12.7/src/jvm/clojure/lang/PersistentVector.java#L567-L580&quot;&gt;PersistentVector.ChunkedSeq.drop&lt;/a&gt; add the current position and &lt;code&gt;n&lt;/code&gt; as 32-bit ints (&lt;code&gt;i + n&lt;/code&gt;, &lt;code&gt;offset + n&lt;/code&gt;, and &lt;code&gt;i + offset + n&lt;/code&gt;) before comparing with the length, so the sum wraps negative and passes the &lt;code&gt;&amp;lt;&lt;/code&gt; check. Comparing &lt;code&gt;n&lt;/code&gt; with the remaining length keeps the check in range.&lt;/p&gt;
&lt;p&gt;This is separate from &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2787&quot;&gt;CLJ-2787&lt;/a&gt;, where &lt;code&gt;n&lt;/code&gt; itself doesn&#039;t fit in an int.&lt;/p&gt;
&lt;p&gt;This bug is 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>Sequences</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/15311/string-vector-returns-broken-integer-maxvalue-regression</guid>
<pubDate>Thu, 03 Dec 2026 20:08:54 +0000</pubDate>
</item>
</channel>
</rss>