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

Chris Hegarty chegar at openjdk.java.net
Thu Nov 19 19:40:11 UTC 2020


On Thu, 19 Nov 2020 17:11:49 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> After starting some of the work to improve NPE handling on foreign-abi, I realized that what I was doing was indeed mechanical, and very amenable to a single, centralized test which sends null into all reference-accepting API methods.
> 
> The new test, `TestNull` takes care of this task; it is much easier to maintain, as, moving forward, we only need to add new classes to the tests, or add methods to the exclude list.
> 
> For each method featuring at least one reference type, the test creates some default values for the non-reference parameters, and then a bunch of replacements for the reference parameter. The replacement could simply be `null`, but in the case of arrays and collections more complex replacements are provided (e.g. arrays and collections with null elements).
> 
> Both replacements and default values can be easily added by tweaking some of the test static initializers. An exclusion list is also provided for those APIs which are deliberately null-friendly.
> 
> This patch also reverts the test changes from yesterday's PR, and also some of the null-related tests which has been added in the past.

test/jdk/java/foreign/TestNulls.java line 93:

> 91:             "jdk.incubator.foreign.GroupLayout/withAttribute(java.lang.String,java.lang.constant.Constable)/1/0",
> 92:             "jdk.incubator.foreign.MemoryHandles/insertCoordinates(java.lang.invoke.VarHandle,int,java.lang.Object[])/2/1"
> 93:     );

This is the set of API points, and parameter positions, that accept null. Cool to have this in one place.

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

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


More information about the panama-dev mailing list