[foreign-memaccess] RFR: 8256466: MemoryLayout factories do not guard against null layouts
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Thu Nov 19 20:54:09 UTC 2020
On Thu, 19 Nov 2020 19:37:13 GMT, Chris Hegarty <chegar 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.
Yeah - it's a bit "stringy" and maybe can be improved, but compared to what we had before, I think it's a massive improvement :-)
If you are curious about the encoding it's (but you probably have figured it out):
<className> / <method signature> / <index of the parameter to be replaced> / <index of the replacement to be used>
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/397
More information about the panama-dev
mailing list