vigna / fastutil

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

Iterating on sublist causes an IndexOutOfBounds exception #328

Closed dadlefish closed 1 month ago

dadlefish commented 1 month ago

This code:

  public static void main(String[] args){
    IntImmutableList fullList = IntImmutableList.of(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15);
    IntList sublist = fullList.subList(5, 8);
    for (int i : sublist) {
      System.out.println(i);
    }
  }

Causes this exception:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index (5) is greater than or equal to list size (3)
    at it.unimi.dsi.fastutil.ints.AbstractIntList.ensureRestrictedIndex(AbstractIntList.java:66)
    at it.unimi.dsi.fastutil.ints.IntImmutableList$ImmutableSubList.listIterator(IntImmutableList.java:466)
    at it.unimi.dsi.fastutil.ints.AbstractIntList.listIterator(AbstractIntList.java:152)
    at it.unimi.dsi.fastutil.ints.AbstractIntList.iterator(AbstractIntList.java:142)
    at ___.main(___.java:149)
vigna commented 1 month ago

Cannot reproduce with the current version.

dadlefish commented 1 month ago

Verified - indeed this happened in 8.5.13 and no longer happens.