JDK-8288761 : SegmentAllocator:allocate(long bytesSize) not throwing IAEx when bytesSize < 0
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.foreign
  • Affected Version: 19,19.0.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-06-20
  • Updated: 2022-07-27
  • Resolved: 2022-06-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19 JDK 20
19 b28Fixed 20Fixed
Related Reports
Relates :  
Description
As per spec : https://download.java.net/java/early_access/jdk19/docs/api/java.base/java/lang/foreign/SegmentAllocator.html#allocate(long)
Throws:
IllegalArgumentException - if bytesSize < 0

Observed that IAEx is thrown only for SegmentAllocator created with implicitAllocator() not for others.

Attached the sample to demonstrate the issue.
Comments
Changeset: d7b43af5 Author: Maurizio Cimadamore <mcimadamore@openjdk.org> Date: 2022-06-21 20:59:45 +0000 URL: https://git.openjdk.org/jdk19/commit/d7b43af5914d88e5410f33db8b56f4dabdfec25d
21-06-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk19/pull/50 Date: 2022-06-20 21:22:42 +0000
20-06-2022

Confirmed - instead of IAE, another exception is reported. MemorySegment{ id=0x59a10c26 limit: 4096 }; new offset = 0; new length = -1 | at AbstractMemorySegmentImpl.outOfBoundException (AbstractMemorySegmentImpl.java:404) | at AbstractMemorySegmentImpl.checkBounds (AbstractMemorySegmentImpl.java:387) | at AbstractMemorySegmentImpl.asSlice (AbstractMemorySegmentImpl.java:103) | at AbstractMemorySegmentImpl.asSlice (AbstractMemorySegmentImpl.java:68) | at ArenaAllocator.trySlice (ArenaAllocator.java:57) | at ArenaAllocator.allocate (ArenaAllocator.java:75) | at SegmentAllocator.allocate (SegmentAllocator.java:326) | at (#2:1)
20-06-2022