File tree Expand file tree Collapse file tree
objectbox-java/src/main/java/io/objectbox/query
tests/objectbox-java-test/src/test/java/io/objectbox/query Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -278,6 +278,9 @@ public ListIterator<E> listIterator() {
278278
279279 @ Override
280280 public ListIterator <E > listIterator (int location ) {
281+ if (location < 0 || location > size ) {
282+ throw new IndexOutOfBoundsException ("Index: " + location + ", Size: " + size );
283+ }
281284 return new LazyIterator (location );
282285 }
283286
Original file line number Diff line number Diff line change @@ -176,6 +176,29 @@ public void testUncached() {
176176 }
177177 }
178178
179+ @ Test
180+ public void listIterator_indexOutOfBounds_throws () {
181+ putTestEntities (3 );
182+ LazyList <TestEntity > listLazy = getTestEntityBox ().query ().build ().findLazyCached ();
183+ int size = listLazy .size ();
184+
185+ try {
186+ listLazy .listIterator (-1 );
187+ fail ("listIterator should throw for negative index" );
188+ } catch (IndexOutOfBoundsException expected ) {
189+ // Expected, OK
190+ }
191+
192+ try {
193+ listLazy .listIterator (size + 1 );
194+ fail ("listIterator should throw for index larger than size" );
195+ } catch (IndexOutOfBoundsException expected ) {
196+ // Expected, OK
197+ }
198+
199+ assertNotNull (listLazy .listIterator (size ));
200+ }
201+
179202
180203 protected void assertIds (List <TestEntity > list , List <TestEntity > list2 ) {
181204 for (int i = 0 ; i < list .size (); i ++) {
You can’t perform that action at this time.
0 commit comments