Closed
Description
If I use the forEach()
method of Any
on an empty array, a IndexOutOfBoundsException is thrown.
Simple example to reproduce:
Any a = JsonIterator.deserialize("[[\"Foo\",\"Bar\"],[]]");
a.forEach(b -> b.forEach(c -> System.out.println(c.toString())));
This results in:
Foo
Bar
Exception in thread "main" java.lang.IndexOutOfBoundsException
at com.jsoniter.any.ArrayLazyAny.fillCacheUntil(ArrayLazyAny.java:163)
at com.jsoniter.any.ArrayLazyAny.access$000(ArrayLazyAny.java:13)
at com.jsoniter.any.ArrayLazyAny$LazyIterator.<init>(ArrayLazyAny.java:197)
at com.jsoniter.any.ArrayLazyAny.iterator(ArrayLazyAny.java:79)
at java.lang.Iterable.forEach(Iterable.java:74)
...
A simple workaround is to get the array as a list and use the forEach()
method of the list:
Any a = JsonIterator.deserialize("[[\"Foo\",\"Bar\"],[]]");
a.forEach(b -> b.asList().forEach(c -> System.out.println(c.toString())));
The dependency I used in my pom.xml
:
<dependency>
<groupId>com.jsoniter</groupId>
<artifactId>jsoniter</artifactId>
<version>0.9.22</version>
</dependency>
Am I doing something wrong or is this a bug?
Thank you!
Metadata
Metadata
Assignees
Labels
No labels