vigna / fastutil

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

ArrayIndexOutOfBoundsException in the iterator of subList of the IntImmutableList #321

Open MartinTunzer-TomTom opened 5 months ago

MartinTunzer-TomTom commented 5 months ago

Version 8.5.12 How to reproduce:

IntList list = new IntArrayList();
list.add(1);
list.add(2);
list.add(3);

list = new IntImmutableList(list);

IntList subList = list.subList(1, 3);

for (int i : subList) {
    System.out.println("i = " + i);
}

gives:

i = 2
i = 3
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
    at it.unimi.dsi.fastutil.ints.IntImmutableList$ImmutableSubList$1.nextInt(IntImmutableList.java:483)
    at it.unimi.dsi.fastutil.ints.IntIterator.next(IntIterator.java:46)
    at it.unimi.dsi.fastutil.ints.IntListIterator.next(IntListIterator.java:103)
    at it.unimi.dsi.fastutil.ints.IntListIterator.next(IntListIterator.java:31)
vigna commented 5 months ago

This should be fixed in the GitHub code. Can you check whether this is the case ? I'm gonna do a release ASAP.