-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
22
As per the spec - https://download.java.net/java/early_access/jdk22/docs/api/java.base/java/lang/foreign/SegmentAllocator.html#allocate(java.lang.foreign.MemoryLayout,long)
Throws:
IllegalArgumentException - if elementLayout.byteSize() * count overflows
actually - java.lang.IndexOutOfBoundsException is thrown.
Is it a typo in the spec?
sample code
===
private void test01() {
SegmentAllocator segmentAllocator = SegmentAllocator.prefixAllocator(MemorySegment.ofArray(new byte[4]));
try {
segmentAllocator.allocate(ValueLayout.JAVA_BYTE, 5);
}catch (IllegalArgumentException ex){
System.out.println("Expected ");
} catch (Throwable t){
System.out.println("actual is "+t);
}
}
===
output:
actual is java.lang.IndexOutOfBoundsException
Throws:
IllegalArgumentException - if elementLayout.byteSize() * count overflows
actually - java.lang.IndexOutOfBoundsException is thrown.
Is it a typo in the spec?
sample code
===
private void test01() {
SegmentAllocator segmentAllocator = SegmentAllocator.prefixAllocator(MemorySegment.ofArray(new byte[4]));
try {
segmentAllocator.allocate(ValueLayout.JAVA_BYTE, 5);
}catch (IllegalArgumentException ex){
System.out.println("Expected ");
} catch (Throwable t){
System.out.println("actual is "+t);
}
}
===
output:
actual is java.lang.IndexOutOfBoundsException