JDK-8289365 : SegmentAllocator:allocateArray(MemoryLayout, count) does not throw IAEx when count is -1
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.foreign
  • Affected Version: 19
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2022-06-28
  • Updated: 2022-07-27
  • Resolved: 2022-07-12
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 b31Fixed 20Fixed
Related Reports
Relates :  
Description
The spec : https://download.java.net/java/early_access/jdk19/docs/api/java.base/java/lang/foreign/SegmentAllocator.html#allocate(java.lang.foreign.MemoryLayout)
"Throws:
IllegalArgumentException - if count < 0."

Expecting the below code shall throw IAEx.

 try {
            SegmentAllocator.implicitAllocator().allocateArray(ValueLayout.JAVA_BYTE, -1);
        }catch (IllegalArgumentException ex){
            System.out.println("OK - Expected Exception ");
        }catch (Exception ex){
            System.out.println("NOT OK - exception thrown is "+ex.getMessage());
        }

Actual Result :
java.lang.OutOfMemoryError: Cannot reserve 1152921504606846975 bytes...


Note - For other negative numbers the implementation throws IAEx.

Comments
Changeset: 4545ed68 Author: Maurizio Cimadamore <mcimadamore@openjdk.org> Date: 2022-07-12 14:22:42 +0000 URL: https://git.openjdk.org/jdk19/commit/4545ed6842b1882d64f62f96b7abdfc2b3d043b8
12-07-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk19/pull/132 Date: 2022-07-11 14:45:42 +0000
11-07-2022