On Wed, 4 Mar 2026 03:01:20 GMT, Sergey Bylokhov <[email protected]> wrote:
>> This method and its usage seem suspicious, how should a negative index i be >> handled, is it allowed? >> >> Is the size actually "a size" of the array the buffer stored? It seems that >> it is the number of items in the array: >> Example: new DataBufferInt(new int[8], 5, 3) >> How should the next be validated: i = 2, offset = 3, size = 5 ->> "(2+3) >= >> 5" ->> BOOM? > > This code worked before: > > DataBufferInt buf = new DataBufferInt(new int[8], 5, 3); > buf.setElem(2, 42); > > and failed after this patch: > ` Invalid index (offset+i) is (3 + 2) which is too large for size : 5` I think you are right, this should disallow negative i. The spec (even before this change) says Only elements offset through offset + size - 1 should be used by accessors of this DataBuffer. A negative index would allow accessing elements before 'offset' I'm fixing that now. size is not the array length. That could be much larger. size limits the elements you can access. The example that fails above is disallowed by the above spec. statement which was not previously enforced. The CSR for this issue calls this out in the problem statement text. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29766#discussion_r2886601187
