spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

DefaultRedisList.get(int) does not reject an index equal to the list size

Open ryujungkyun opened this issue 1 month ago • 0 comments

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

  1. Create a DefaultRedisList containing three elements.
  2. Call get(3).
  3. Observe that the expected IndexOutOfBoundsException is 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

ryujungkyun avatar Oct 15 '26 06:10 ryujungkyun