vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.74k stars 194 forks source link

Error in ImmutableSubList.ListIterator#hasNext #307

Open meztihn opened 9 months ago

meztihn commented 9 months ago

Example:

var iterator = IntList.of(1, 1).subList(1, 2).iterator();
while (iterator.hasNext()) iterator.nextInt();

throws java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2. It's reproducible with DoubleList as well. Haven't checked other types though.

Possible workaround: replace IntList with IntArrayList.

Affected version: fastutil-core:8.5.12.

I guess, the problem is in missing addition of from inside hasNext method.

techsy730 commented 7 months ago

Sounds like a (hopefully) simple fix; I can try to make a merge request for it

vigna commented 7 months ago

Ouch, I completely missed this somehow. Yes, if you can fix it in a PR that'd be great. I'd like to fix a few things and release.