spring-data-redis
spring-data-redis copied to clipboard
DefaultRedisList.get(int) does not reject an index equal to the list size
Description
DefaultRedisList.get(int) does not throw IndexOutOfBoundsException when the index equals the list size, contrary to the List.get(int) contract.
The current bounds check uses index > size() instead of index >= size(). This allows an invalid index to reach the underlying Redis operation.
Example
Given a list containing [A, B, C]:
| Call | Expected result |
|---|---|
get(0) |
A |
get(2) |
C |
get(3) |
IndexOutOfBoundsException |
The same issue occurs when calling get(0) on an empty list.
Steps to reproduce
- Create a
DefaultRedisListcontaining three elements. - Call
get(3). - Observe that the expected
IndexOutOfBoundsExceptionis not thrown.
Alternatively, create an empty list and call get(0).
Expected behavior
get(int) should throw IndexOutOfBoundsException when index < 0 or index >= size().
Actual behavior
An index equal to size() passes the bounds check and is forwarded to BoundListOperations.index(...) without throwing the expected exception.
Related PR: #3470