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.