renechoi opened a new pull request, #12656:
URL: https://github.com/apache/maven/pull/12656
`SubList.get()` checked `index > size()`, so an index equal to the sub
list's size passed and reached `AbstractImmutableList.this.get(fromIndex +
index)`.
The issue describes this as surfacing an `IndexOutOfBoundsException` from
the parent instead of a clear one from the sub list. That is what happens when
the sub list reaches the end of its parent, and the exception is an
`ArrayIndexOutOfBoundsException` from the backing array. When the sub list
stops earlier there is no exception at all: the parent resolves the index and
returns an element the sub list does not contain.
```java
List<String> list = ImmutableCollections.copy(List.of("a", "b", "c"));
list.subList(0, 1).get(1); // "b" before
list.subList(0, 1).get(1); // IndexOutOfBoundsException: Index: 1, Size: 1
after
list.subList(2, 3).get(1); // ArrayIndexOutOfBoundsException: Index 3 out
of bounds for length 3 before
```
`ListN.get()` indexes the array directly and has no bounds check of its own,
which is why a read past the sub list is silent.
The same class is checked in three times: the mdo template plus the two
copies generated from it under `api/maven-api-xml` and `impl/maven-xml`. All
three are fixed, since changing only the copies would let the next regeneration
bring it back.
`listIterator(int)` a few lines above keeps `index > size()`. That bound is
correct there because `List.listIterator(int)` accepts `size()` as a cursor
position, so one of the added tests pins it to prevent the two being aligned
later by mistake.
Tests: four cases in a new `ImmutableCollectionsTest` in `impl/maven-xml`,
covering the equal-to-size index, the read past a sub list that ends early,
negative indices, and the `listIterator` bound. Two of them fail on
`maven-4.0.x` and pass with this change; the module suite is green at 75 tests
with checkstyle and spotless enabled.
Fixes #12595
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]