From ae07dba19b20087b57cebe8644acd48d9905813e Mon Sep 17 00:00:00 2001 From: Florin Braghis Date: Sat, 7 Jun 2025 10:52:41 +0200 Subject: [PATCH 1/3] Throw exception if requested index is out of bounds --- src/xitdb/array_list.clj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/xitdb/array_list.clj b/src/xitdb/array_list.clj index 2a7e67d..82b18d6 100644 --- a/src/xitdb/array_list.clj +++ b/src/xitdb/array_list.clj @@ -40,8 +40,11 @@ clojure.lang.Indexed (nth [_ i] - (let [cursor (.getCursor ral (long i))] - (common/-read-from-cursor cursor))) + (let [count (.count ral) + idx (long i)] + (if (and (>= idx 0) (< idx count)) + (common/-read-from-cursor (.getCursor ral idx)) + (throw (IndexOutOfBoundsException. (str "Index: " i ", Size: " count)))))) (nth [_ i not-found] (let [cursor (.getCursor ral (long i))] From e9e21e1de1b92398a6847a81501a5459556e4791 Mon Sep 17 00:00:00 2001 From: Florin Braghis Date: Sat, 7 Jun 2025 10:58:01 +0200 Subject: [PATCH 2/3] Add unit test --- test/xitdb/cursor_test.clj | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/xitdb/cursor_test.clj b/test/xitdb/cursor_test.clj index adcae77..acbe375 100644 --- a/test/xitdb/cursor_test.clj +++ b/test/xitdb/cursor_test.clj @@ -24,4 +24,7 @@ (swap! cursor1 assoc-in [3 :hidden] :changed-by-swap!) (is (= [1 2 3 {:hidden :changed-by-swap!} 5]) (xdb/materialize @cursor1)) (is (= :changed-by-swap! @cursor3)) - (is (= 3 @cursor2)))))) + (is (= 3 @cursor2))) + + (testing "Correctly handles invalid cursor path" + (is (thrown? IndexOutOfBoundsException @(xdb/xdb-cursor db [:foo :bar 999]))))))) From 0afa8cfb55e92e6aa6a086141bed60a8b6ee0326 Mon Sep 17 00:00:00 2001 From: Florin Braghis Date: Sun, 8 Jun 2025 12:38:51 +0200 Subject: [PATCH 3/3] Fix typehint --- src/xitdb/util/operations.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/xitdb/util/operations.clj b/src/xitdb/util/operations.clj index 01950c2..410bf78 100644 --- a/src/xitdb/util/operations.clj +++ b/src/xitdb/util/operations.clj @@ -185,7 +185,7 @@ cursor (.getCursor rhs hash-code)] (some? cursor))) -(defn ^WriteHashMap set-empty! +(defn ^WriteHashSet set-empty! "Replaces the whs value with an empty set." [^WriteHashSet whs] (let [empty-set (conversion/v->slot! (.cursor whs) #{})]