Skip to content

Commit a6d64e7

Browse files
committed
json-iterator#40 fix iterator tail
1 parent b4acf9b commit a6d64e7

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/main/java/com/jsoniter/any/ArrayLazyAny.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,16 @@ public boolean hasNext() {
202202

203203
@Override
204204
public Any next() {
205+
if (next == null) {
206+
throw new IndexOutOfBoundsException();
207+
}
205208
Any current = next;
206-
index++;
207-
next = fillCacheUntil(index);
209+
try {
210+
index++;
211+
next = fillCacheUntil(index);
212+
} catch (IndexOutOfBoundsException e){
213+
next = null;
214+
}
208215
return current;
209216
}
210217
}

src/test/java/com/jsoniter/any/TestArray.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,7 @@ public void test_fill_partial_then_iterate() {
6060
Iterator<Any> iter = obj.iterator();
6161
assertEquals(1, iter.next().toInt());
6262
assertEquals(2, iter.next().toInt());
63+
assertEquals(3, iter.next().toInt());
64+
assertFalse(iter.hasNext());
6365
}
6466
}

0 commit comments

Comments
 (0)