RFR: Add checks to reject creation of non-empty null-restricted arrays w/o initializer

Vicente Romero vromero at openjdk.org
Fri Jan 9 13:47:14 UTC 2026


On Fri, 9 Jan 2026 12:28:59 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This PR adds checks in `Attr` so that creation of non-empty null-restricted arrays w/o an initializer is not allowed.
> 
> The code is very careful in determining situations where null-restrictions on the array element type are irrelevant, such as:
> 
> * when the array size is a constant zero - `new String![0]` -- as in this case the restricted array is empty, so there's nothing to initialize
> * when one or more dimensions are missing - `new String![10][]` -- as in this case the outer array (of size 10) is just filled with `null`s, as the inner array lacks a size
> * when one or more intermediate dimensions is the constant zero - `new String[0][10]` -- as in this case nothing is really created, as the outer array is empty
> 
> A test has been added to (hopefully) cover all such pesky cases.

lgtm

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

Marked as reviewed by vromero (Committer).

PR Review: https://git.openjdk.org/valhalla/pull/1876#pullrequestreview-3643986289


More information about the valhalla-dev mailing list