RFR: 8346657: Improve out of bounds exception messages for MemorySegments [v11]

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Dec 2 17:35:00 UTC 2025


On Tue, 2 Dec 2025 13:10:09 GMT, Igor Rudenko <duke at openjdk.org> wrote:

>> Logic for creating IndexOutOfBoundsException in MemorySegment is reworked:
>> - separate logic of checking bounds and constructing exception messages for both `access` and `slice` cases 
>> - idea presented in [JDK-8288534](https://bugs.openjdk.org/browse/JDK-8288534) slightly reworked with preservation of the original approach
>
> Igor Rudenko has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Improvements according to reviewer's advices

I like the new approach!

src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 421:

> 419:     @ForceInline
> 420:     private void checkBounds(long offset, long length) {
> 421:         if (length > 0) {

Note: if we know we're not coming from a slice operation, we can just drop the if... so I wonder if we could split the impl in two to remove extra branches in the access case?

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

Marked as reviewed by mcimadamore (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/28124#pullrequestreview-3531359065
PR Review Comment: https://git.openjdk.org/jdk/pull/28124#discussion_r2582188436


More information about the core-libs-dev mailing list