8289228: SegmentAllocator::allocateArray null handling is too lax

Reviewed-by: jvernee, psandoz
This commit is contained in:
Maurizio Cimadamore 2022-06-28 10:06:42 +00:00
parent b4490386fe
commit adbd200dc5
2 changed files with 3 additions and 16 deletions

View File

@ -282,8 +282,9 @@ public interface SegmentAllocator {
private <Z> MemorySegment copyArrayWithSwapIfNeeded(Z array, ValueLayout elementLayout,
Function<Z, MemorySegment> heapSegmentFactory) {
Objects.requireNonNull(array);
Objects.requireNonNull(elementLayout);
int size = array == null ? 0 : Array.getLength(array);
int size = Array.getLength(array);
MemorySegment addr = allocateArray(elementLayout, size);
if (size > 0) {
MemorySegment.copy(heapSegmentFactory.apply(array), elementLayout, 0,

View File

@ -121,21 +121,7 @@ public class TestNulls {
"java.lang.foreign.ValueLayout$OfLong/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
"java.lang.foreign.ValueLayout$OfDouble/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
"java.lang.foreign.GroupLayout/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
"java.lang.foreign.FunctionDescriptor/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfByte,byte[])/1/0",
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfShort,short[])/1/0",
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfChar,char[])/1/0",
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfInt,int[])/1/0",
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfFloat,float[])/1/0",
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfLong,long[])/1/0",
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfDouble,double[])/1/0",
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfByte,byte[])/1/0",
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfShort,short[])/1/0",
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfChar,char[])/1/0",
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfInt,int[])/1/0",
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfFloat,float[])/1/0",
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfLong,long[])/1/0",
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfDouble,double[])/1/0"
"java.lang.foreign.FunctionDescriptor/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0"
);
static final Set<String> OBJECT_METHODS = Stream.of(Object.class.getMethods())