Integrated: 8288534: Out of bound errors for memory segment access mentions wrong values

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Jun 16 16:04:54 UTC 2022


On Wed, 15 Jun 2022 21:24:04 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> While playing with the API, I've realized that some of the out of bound error messgaes come out incorrectly.
> 
> This is because the bound check is performed as follows (to avoid overflow):
> 
> 
> Objects.checkIndex(offset, this.length - length + 1);
> 
> 
> So, if out-of-bounds access is detected, the resulting exception mentions the values of the first and second parameter, respectively - but since the second parameter is the result of a subtraction, it doesn't make sense.
> 
> The solution is not to use `Objects.checkIndex` directly, but, instead, drop down one level, and pass our own "IOOB formatter":
> 
> 
> Preconditions.checkIndex(offset, this.length - length + 1, this);
> 
> 
> Note that, in order to recover the correct values, the formatter needs to know the segment size - so I made `AbstractMemorySegment` act as a formatter (so we don't need to allocate in such a hot path).
> 
> The fix seems to bring back the desired messages - but I would like some confirmation that doing this won't disrupt intrinsification of the `checkIndex` method.

This pull request has now been integrated.

Changeset: ff3db520
Author:    Maurizio Cimadamore <mcimadamore at openjdk.org>
URL:       https://git.openjdk.org/jdk19/commit/ff3db52044f69754b1ccf54961f453d4afbfba3a
Stats:     26 lines in 3 files changed: 23 ins; 0 del; 3 mod

8288534: Out of bound errors for memory segment access mentions wrong values

Reviewed-by: psandoz

-------------

PR: https://git.openjdk.org/jdk19/pull/24


More information about the core-libs-dev mailing list