> 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.
Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision: Add @ForceInline on AbstractLayout::byteSize ------------- Changes: - all: https://git.openjdk.org/jdk19/pull/24/files - new: https://git.openjdk.org/jdk19/pull/24/files/ebbc356c..8b15d0fc Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk19&pr=24&range=01 - incr: https://webrevs.openjdk.org/?repo=jdk19&pr=24&range=00-01 Stats: 2 lines in 1 file changed: 2 ins; 0 del; 0 mod Patch: https://git.openjdk.org/jdk19/pull/24.diff Fetch: git fetch https://git.openjdk.org/jdk19 pull/24/head:pull/24 PR: https://git.openjdk.org/jdk19/pull/24