36
36
import java .nio .charset .Charset ;
37
37
import java .util .Objects ;
38
38
import java .util .function .Consumer ;
39
+ import java .util .stream .Stream ;
39
40
40
41
import static jdk .internal .foreign .PlatformLayouts .*;
41
42
94
95
* {@link #asVarArg(MemoryLayout)} is used to create the memory layouts for each parameter corresponding to a variadic
95
96
* argument in a specialized function descriptor.
96
97
*
98
+ * <p> Unless otherwise specified, passing a {@code null} argument, or an array argument containing one or more {@code null}
99
+ * elements to a method in this class causes a {@link NullPointerException NullPointerException} to be thrown. </p>
100
+ *
97
101
* @apiNote In the future, if the Java language permits, {@link CLinker}
98
102
* may become a {@code sealed} interface, which would prohibit subclassing except by
99
103
* explicitly permitted types.
@@ -186,14 +190,16 @@ static CLinker getInstance() {
186
190
MemoryLayout C_VA_LIST = pick (SysV .C_VA_LIST , Win64 .C_VA_LIST , AArch64 .C_VA_LIST );
187
191
188
192
/**
189
- * Returns a memory layout that is suitable to use the layout for variadic arguments.
193
+ * Returns a memory layout that is suitable to use as the layout for variadic arguments in a specialized
194
+ * function descriptor.
190
195
* @param <T> the memory layout type
191
- * @param ml the layout the adapt
196
+ * @param layout the layout the adapt
192
197
* @return a potentially newly created layout with the right attributes
193
198
*/
194
199
@ SuppressWarnings ("unchecked" )
195
- static <T extends MemoryLayout > T asVarArg (T ml ) {
196
- return (T ) PlatformLayouts .asVarArg (ml );
200
+ static <T extends MemoryLayout > T asVarArg (T layout ) {
201
+ Objects .requireNonNull (layout );
202
+ return (T ) PlatformLayouts .asVarArg (layout );
197
203
}
198
204
199
205
/**
@@ -207,7 +213,6 @@ static <T extends MemoryLayout> T asVarArg(T ml) {
207
213
*
208
214
* @param str the Java string to be converted into a C string.
209
215
* @return a new native memory segment containing the converted C string.
210
- * @throws NullPointerException if {@code str == null}.
211
216
*/
212
217
static MemorySegment toCString (String str ) {
213
218
Objects .requireNonNull (str );
@@ -226,7 +231,6 @@ static MemorySegment toCString(String str) {
226
231
* @param str the Java string to be converted into a C string.
227
232
* @param charset The {@link java.nio.charset.Charset} to be used to compute the contents of the C string.
228
233
* @return a new native memory segment containing the converted C string.
229
- * @throws NullPointerException if either {@code str == null} or {@code charset == null}.
230
234
*/
231
235
static MemorySegment toCString (String str , Charset charset ) {
232
236
Objects .requireNonNull (str );
@@ -246,7 +250,6 @@ static MemorySegment toCString(String str, Charset charset) {
246
250
* @param str the Java string to be converted into a C string.
247
251
* @param scope the scope to be used for the native segment allocation.
248
252
* @return a new native memory segment containing the converted C string.
249
- * @throws NullPointerException if either {@code str == null} or {@code scope == null}.
250
253
*/
251
254
static MemorySegment toCString (String str , NativeScope scope ) {
252
255
Objects .requireNonNull (str );
@@ -267,7 +270,6 @@ static MemorySegment toCString(String str, NativeScope scope) {
267
270
* @param charset The {@link java.nio.charset.Charset} to be used to compute the contents of the C string.
268
271
* @param scope the scope to be used for the native segment allocation.
269
272
* @return a new native memory segment containing the converted C string.
270
- * @throws NullPointerException if either {@code str == null}, {@code charset == null} or {@code scope == null}.
271
273
*/
272
274
static MemorySegment toCString (String str , Charset charset , NativeScope scope ) {
273
275
Objects .requireNonNull (str );
@@ -289,11 +291,11 @@ static MemorySegment toCString(String str, Charset charset, NativeScope scope) {
289
291
* restricted methods, and use safe and supported functionalities, where possible.
290
292
* @param addr the address at which the string is stored.
291
293
* @return a Java string with the contents of the null-terminated C string at given address.
292
- * @throws NullPointerException if {@code addr == null}
293
294
* @throws IllegalArgumentException if the size of the native string is greater than the largest string supported by the platform.
294
295
*/
295
296
static String toJavaStringRestricted (MemoryAddress addr ) {
296
297
Utils .checkRestrictedAccess ("CLinker.toJavaStringRestricted" );
298
+ Objects .requireNonNull (addr );
297
299
return SharedUtils .toJavaStringInternal (NativeMemorySegmentImpl .EVERYTHING , addr .toRawLongValue (), Charset .defaultCharset ());
298
300
}
299
301
@@ -311,7 +313,6 @@ static String toJavaStringRestricted(MemoryAddress addr) {
311
313
* @param addr the address at which the string is stored.
312
314
* @param charset The {@link java.nio.charset.Charset} to be used to compute the contents of the Java string.
313
315
* @return a Java string with the contents of the null-terminated C string at given address.
314
- * @throws NullPointerException if {@code addr == null} or {@code charset == null}.
315
316
* @throws IllegalArgumentException if the size of the native string is greater than the largest string supported by the platform.
316
317
*/
317
318
static String toJavaStringRestricted (MemoryAddress addr , Charset charset ) {
@@ -330,7 +331,6 @@ static String toJavaStringRestricted(MemoryAddress addr, Charset charset) {
330
331
* over the decoding process is required.
331
332
* @param addr the address at which the string is stored.
332
333
* @return a Java string with the contents of the null-terminated C string at given address.
333
- * @throws NullPointerException if {@code addr == null}
334
334
* @throws IllegalArgumentException if the size of the native string is greater than the largest string supported by the platform.
335
335
* @throws IllegalStateException if the size of the native string is greater than the size of the segment
336
336
* associated with {@code addr}, or if {@code addr} is associated with a segment that is <em>not alive</em>.
@@ -350,7 +350,6 @@ static String toJavaString(MemorySegment addr) {
350
350
* @param addr the address at which the string is stored.
351
351
* @param charset The {@link java.nio.charset.Charset} to be used to compute the contents of the Java string.
352
352
* @return a Java string with the contents of the null-terminated C string at given address.
353
- * @throws NullPointerException if {@code addr == null} or {@code charset == null}.
354
353
* @throws IllegalArgumentException if the size of the native string is greater than the largest string supported by the platform.
355
354
* @throws IllegalStateException if the size of the native string is greater than the size of the segment
356
355
* associated with {@code addr}, or if {@code addr} is associated with a segment that is <em>not alive</em>.
@@ -408,7 +407,6 @@ static MemoryAddress allocateMemoryRestricted(long size) {
408
407
* restricted methods, and use safe and supported functionalities, where possible.
409
408
*
410
409
* @param addr memory address of the native memory to be freed
411
- * @throws NullPointerException if {@code addr == null}.
412
410
*/
413
411
static void freeMemoryRestricted (MemoryAddress addr ) {
414
412
Utils .checkRestrictedAccess ("CLinker.freeMemoryRestricted" );
@@ -429,6 +427,9 @@ static void freeMemoryRestricted(MemoryAddress addr) {
429
427
* As such, this interface only supports reading {@code int}, {@code double},
430
428
* and any other type that fits into a {@code long}.
431
429
*
430
+ * <p> Unless otherwise specified, passing a {@code null} argument, or an array argument containing one or more {@code null}
431
+ * elements to a method in this class causes a {@link NullPointerException NullPointerException} to be thrown. </p>
432
+ *
432
433
* @apiNote In the future, if the Java language permits, {@link VaList}
433
434
* may become a {@code sealed} interface, which would prohibit subclassing except by
434
435
* explicitly permitted types.
@@ -597,6 +598,7 @@ interface VaList extends Addressable, AutoCloseable {
597
598
*/
598
599
static VaList ofAddressRestricted (MemoryAddress address ) {
599
600
Utils .checkRestrictedAccess ("VaList.ofAddressRestricted" );
601
+ Objects .requireNonNull (address );
600
602
return SharedUtils .newVaListOfAddress (address );
601
603
}
602
604
@@ -618,6 +620,7 @@ static VaList ofAddressRestricted(MemoryAddress address) {
618
620
* @return a new {@code VaList} instance backed by a fresh C {@code va_list}.
619
621
*/
620
622
static VaList make (Consumer <Builder > actions ) {
623
+ Objects .requireNonNull (actions );
621
624
return SharedUtils .newVaList (actions , MemorySegment ::allocateNative );
622
625
}
623
626
@@ -639,6 +642,8 @@ static VaList make(Consumer<Builder> actions) {
639
642
* @return a new {@code VaList} instance backed by a fresh C {@code va_list}.
640
643
*/
641
644
static VaList make (Consumer <Builder > actions , NativeScope scope ) {
645
+ Objects .requireNonNull (actions );
646
+ Objects .requireNonNull (scope );
642
647
return SharedUtils .newVaList (actions , SharedUtils .Allocator .ofScope (scope ));
643
648
}
644
649
@@ -656,6 +661,9 @@ static VaList empty() {
656
661
/**
657
662
* A builder interface used to construct a C {@code va_list}.
658
663
*
664
+ * <p> Unless otherwise specified, passing a {@code null} argument, or an array argument containing one or more {@code null}
665
+ * elements to a method in this class causes a {@link NullPointerException NullPointerException} to be thrown. </p>
666
+ *
659
667
* @apiNote In the future, if the Java language permits, {@link Builder}
660
668
* may become a {@code sealed} interface, which would prohibit subclassing except by
661
669
* explicitly permitted types.
0 commit comments