Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit adbd200

Browse files
committed
8289228: SegmentAllocator::allocateArray null handling is too lax
Reviewed-by: jvernee, psandoz
1 parent b449038 commit adbd200

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

src/java.base/share/classes/java/lang/foreign/SegmentAllocator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ default MemorySegment allocateArray(ValueLayout.OfDouble elementLayout, double..
282282

283283
private <Z> MemorySegment copyArrayWithSwapIfNeeded(Z array, ValueLayout elementLayout,
284284
Function<Z, MemorySegment> heapSegmentFactory) {
285+
Objects.requireNonNull(array);
285286
Objects.requireNonNull(elementLayout);
286-
int size = array == null ? 0 : Array.getLength(array);
287+
int size = Array.getLength(array);
287288
MemorySegment addr = allocateArray(elementLayout, size);
288289
if (size > 0) {
289290
MemorySegment.copy(heapSegmentFactory.apply(array), elementLayout, 0,

test/jdk/java/foreign/TestNulls.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,7 @@ public class TestNulls {
121121
"java.lang.foreign.ValueLayout$OfLong/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
122122
"java.lang.foreign.ValueLayout$OfDouble/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
123123
"java.lang.foreign.GroupLayout/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
124-
"java.lang.foreign.FunctionDescriptor/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
125-
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfByte,byte[])/1/0",
126-
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfShort,short[])/1/0",
127-
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfChar,char[])/1/0",
128-
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfInt,int[])/1/0",
129-
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfFloat,float[])/1/0",
130-
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfLong,long[])/1/0",
131-
"java.lang.foreign.SegmentAllocator/allocateArray(java.lang.foreign.ValueLayout$OfDouble,double[])/1/0",
132-
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfByte,byte[])/1/0",
133-
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfShort,short[])/1/0",
134-
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfChar,char[])/1/0",
135-
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfInt,int[])/1/0",
136-
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfFloat,float[])/1/0",
137-
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfLong,long[])/1/0",
138-
"java.lang.foreign.MemorySession/allocateArray(java.lang.foreign.ValueLayout$OfDouble,double[])/1/0"
124+
"java.lang.foreign.FunctionDescriptor/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0"
139125
);
140126

141127
static final Set<String> OBJECT_METHODS = Stream.of(Object.class.getMethods())

0 commit comments

Comments
 (0)