8289365: SegmentAllocator:allocateArray(MemoryLayout, count) does not throw IAEx when count is -1

Reviewed-by: psandoz
This commit is contained in:
Maurizio Cimadamore 2022-07-12 14:22:42 +00:00
parent 0fd1b68972
commit 4545ed6842
2 changed files with 8 additions and 0 deletions

View file

@ -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));
}