8289365: SegmentAllocator:allocateArray(MemoryLayout, count) does not throw IAEx when count is -1
Reviewed-by: psandoz
This commit is contained in:
parent
0fd1b68972
commit
4545ed6842
src/java.base/share/classes/java/lang/foreign
test/jdk/java/foreign
@ -319,6 +319,9 @@ public interface SegmentAllocator {
|
||||
*/
|
||||
default MemorySegment allocateArray(MemoryLayout elementLayout, long count) {
|
||||
Objects.requireNonNull(elementLayout);
|
||||
if (count < 0) {
|
||||
throw new IllegalArgumentException("Negative array size");
|
||||
}
|
||||
return allocate(MemoryLayout.sequenceLayout(count, elementLayout));
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,11 @@ public class TestSegmentAllocators {
|
||||
allocator.allocate(1, 3);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "allocators", expectedExceptions = IllegalArgumentException.class)
|
||||
public void testBadAllocationArrayNegSize(SegmentAllocator allocator) {
|
||||
allocator.allocateArray(ValueLayout.JAVA_BYTE, -1);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = OutOfMemoryError.class)
|
||||
public void testBadArenaNullReturn() {
|
||||
SegmentAllocator segmentAllocator = SegmentAllocator.newNativeArena(MemorySession.openImplicit());
|
||||
|
Loading…
x
Reference in New Issue
Block a user