On Fri, 9 Jan 2026 16:31:13 GMT, Maurizio Cimadamore <[email protected]> 
wrote:

>> Creation of null-restricted arrays are desugared as calls into methods of 
>> the `ArrayCreation` class, as we need to set the "strict" marker on the 
>> created array.
>> Currently the JVM doesn't support creation of null-restricted array for 
>> non-value types, so in this PR I cleaned up the `ArrayCreation` API to 
>> reflect more what javac needs. Also, according to our long term plans, 
>> `ArrayCreation` is really implemented on top of a new primitive in `Array`, 
>> which will be refined later to support creation of arrays with desired flags.
>> 
>> The translation strategy in javac is simple -- given an array initializer `{ 
>> .. }`, we just assign the initializer to a temp variable, then wrap the 
>> initializer using a call to `ArrayCreation::copied` to obtain the new array. 
>> Then we wrap everything in a let expression, so that things compose nicely.
>> 
>> While writing the test I realized that our combo framework failed to report 
>> compilation and execution failures. As I fixed that issue, I realized that a 
>> test I've added (`NullRestrictionReflectiveTest`) was not working correctly, 
>> as it had compilaton issues with some of the combinations and even a latent 
>> issue in signature parsing which I have now fixed.
>
> Maurizio Cimadamore has updated the pull request with a new target base due 
> to a merge or a rebase. The pull request now contains three commits:
> 
>  - Merge branch 'bworld' into strict_array_trans
>  - Add regression test
>    Fix combo framework execution support to report compile/runtime issues
>  - Initial push

src/java.base/share/classes/java/lang/runtime/ArrayCreation.java line 61:

> 59:      */
> 60:     public static Object enumerated(Class<?> componentType, int flags, 
> Object v1) {
> 61:         return copied(componentType, flags, 3, new Object[] { v1 });

length should be `1` in this case

src/java.base/share/classes/java/lang/runtime/ArrayCreation.java line 74:

> 72:      */
> 73:     public static Object enumerated(Class<?> componentType, int flags, 
> Object v1, Object v2) {
> 74:         return copied(componentType, flags, 3, new Object[] { v1, v2 });

length should be `2` this time, I think

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 4304:

> 4302:         tree.elems = translate(tree.elems, types.elemtype(tree.type));
> 4303:         if (tree.strict && tree.elems != null) {
> 4304:             Assert.check(types.dimensions(tree.type) == 1, "Unexpected 
> multi-dimensional null-restricted array");

should this be a compiler error?

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/1877#discussion_r2676820586
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/1877#discussion_r2676818887
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/1877#discussion_r2676827715

Reply via email to