[foreign-memaccess] RFR: 8256466: MemoryLayout factories do not guard against null layouts

Jorn Vernee jvernee at openjdk.java.net
Wed Nov 18 19:38:14 UTC 2020


On Wed, 18 Nov 2020 19:07:22 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> This is a trivial, but a bit bigger than expected patch which fixes mentions of NPEs in the foreign memory access API javadoc. Almost all API points are affected, from memory layouts, to memory segments, etc.   
>> This patch does a number of things:
>> * Document the various possible NPEs with corresponding `@throws` javadoc tags
>> * Add `Objects::requireNotNull calls` where required
>> * Added tests to check for nulls
>> * Added a brand new test for `MemoryAccess`; this is both to check normal behavior, and also to check behavior when it comes to nulls
>
> src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryLayout.java line 454:
> 
>> 452:     private static <Z> Z computePathOp(LayoutPath path, Function<LayoutPath, Z> finalizer,
>> 453:                                        Set<LayoutPath.PathElementImpl.PathKind> badKinds, PathElement... elements) {
>> 454:         for (PathElement e : elements) {
> 
> What if `elements` itself is `null`? Doesn't seem to be covered currently in either impl or doc.

e.g. a case like 
MemoryLayouts.BITS_8_BE.map(UnaryOperator.identity(), null);

-------------

PR: https://git.openjdk.java.net/panama-foreign/pull/395


More information about the panama-dev mailing list