Skip to content

Commit ae07dba

Browse files
committed
Throw exception if requested index is out of bounds
1 parent 87ccef7 commit ae07dba

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/xitdb/array_list.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040

4141
clojure.lang.Indexed
4242
(nth [_ i]
43-
(let [cursor (.getCursor ral (long i))]
44-
(common/-read-from-cursor cursor)))
43+
(let [count (.count ral)
44+
idx (long i)]
45+
(if (and (>= idx 0) (< idx count))
46+
(common/-read-from-cursor (.getCursor ral idx))
47+
(throw (IndexOutOfBoundsException. (str "Index: " i ", Size: " count))))))
4548

4649
(nth [_ i not-found]
4750
(let [cursor (.getCursor ral (long i))]

0 commit comments

Comments
 (0)