Skip to content

Conversation

@hextriclosan
Copy link
Contributor

@hextriclosan hextriclosan commented Nov 4, 2025

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 slightly reworked with preservation of the original approach

Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8346657: Improve out of bounds exception messages for MemorySegments (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28124/head:pull/28124
$ git checkout pull/28124

Update a local copy of the PR:
$ git checkout pull/28124
$ git pull https://git.openjdk.org/jdk.git pull/28124/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28124

View PR using the GUI difftool:
$ git pr show -t 28124

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28124.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 4, 2025

👋 Welcome back hextriclosan! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 4, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot changed the title JDK-8346657: Improve out of bounds exception messages for MemorySegments 8346657: Improve out of bounds exception messages for MemorySegments Nov 4, 2025
@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Nov 4, 2025
@openjdk
Copy link

openjdk bot commented Nov 4, 2025

@hextriclosan The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 4, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 4, 2025

private IndexOutOfBoundsException outOfBoundException(long offset, long length) {
return new IndexOutOfBoundsException(String.format("Out of bound access on segment %s; new offset = %d; new length = %d",
this, offset, length));
return new IndexOutOfBoundsException(String.format("Out of bound access on segment %s; " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new message looks ok, but note that this message is also reused by the asSlice methods. If we want to clarify the messages, perhaps we should think about rearranging the code a bit?

Related note: this is also why the routine that check OOB access needs to worry about length being zero -- because that's a valid value for asSlice (but not for access).

throw outOfBoundException(offset, length);
}
void checkSliceBounds(long offset, long length) {
Preconditions.checkFromIndexSize(offset, length, this.length, this::sliceOutOfBoundException);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this performance-wise neutral? This is on a hot path and captures a lambda every time, need to verify compiler can eliminate this, which I doubt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-libs core-libs-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

3 participants