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 (same in 1.11.4 and on master).

Calling assoc on a subvec with a negative index (from -start to -1) returns normally and writes to the backing vector before the subvec's start.

Expected: IndexOutOfBoundsException, the same as assoc on a regular vector.

(assoc [2 3] -1 :x)
;; => IndexOutOfBoundsException

(def sv (subvec [0 1 2 3 4] 2 4))
(let [s (assoc sv -1 :x)]
  [s (.-v s) (= s sv)])
;; Actual: [[2 3] [0 :x 2 3 4] true]
;; Expected: IndexOutOfBoundsException

assoc-in, update, and a subvec of vector-of behave the same. A subvec starting at 0 or an index below -start throws from the backing vector.

Cause: SubVector.assocN checks only start + i > end and omits the i < 0 check that CLJ-962 added to SubVector.nth.

This bug is reported at https://s.conao3.com/blog/2026/e4f733

Please log in or register to answer this question.

...