elharo opened a new issue, #12595:
URL: https://github.com/apache/maven/issues/12595

   # ImmutableCollections.SubList.get() off-by-one in bounds check
   
   **Found in:** maven-4.0.x branch
   **File:** 
`api/maven-api-xml/src/main/java/org/apache/maven/api/xml/ImmutableCollections.java`
 (line ~245)
   **Severity:** High
   
   ## Description
   
   The `SubList.get()` method has an off-by-one error in its bounds check:
   
   ```java
   public E get(int index) {
       if (index < 0 || index > size()) {    // BUG: should be >=, not >
           throw outOfBounds(index);
       }
       return AbstractImmutableList.this.get(fromIndex + index);
   }
   ```
   
   When `index` equals `size()`, the check passes but the subsequent 
`AbstractImmutableList.this.get(fromIndex + index)` will compute `fromIndex + 
size() == toIndex`, which is out of bounds of the parent list. This causes an 
`IndexOutOfBoundsException` to be thrown from the parent list rather than a 
clear error message from the sublist.


-- 
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]

Reply via email to