RFR: 8374730: Add support for null restriction in j.l.r.Type

Vicente Romero vromero at openjdk.org
Wed Jan 7 17:32:36 UTC 2026


On Wed, 7 Jan 2026 16:03:42 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This PR adds j.l.r.Type support for null restrictions.
> 
> More specifically, a new public interface is added, namely `NullRestrictedType`, modelling types with null restrictions.
> 
> Changes to the signature parsing code have been made so that instances of the new interface are generated accordingly.
> A new test makes sure that everything behaves correctly.
> 
> Note: we should also make sure that the `AnnotatedType` hierarchy is changed to reflect the null-restriction changes, but for now that is lower priority and will be pursued in a separate PR.

src/java.base/share/classes/java/lang/reflect/NullRestrictedType.java line 36:

> 34:  *
> 35:  * <p>Instances of classes that implement this interface must implement
> 36:  * an equals() method that equates any two null rrestricted type instances that

nit: typo `rrestricted`

src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/NullRestrictedTypeImpl.java line 42:

> 40:     }
> 41: 
> 42:     private void checkNonRestricted(Type type) {

can this method be static?

src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/NullRestrictedTypeImpl.java line 44:

> 42:     private void checkNonRestricted(Type type) {
> 43:         if (type instanceof NullRestrictedType) {
> 44:             throw new IllegalArgumentException("Already a null-rrestricted type");

typo: `rrestricted`

src/java.base/share/classes/sun/reflect/generics/reflectiveObjects/NullRestrictedTypeImpl.java line 65:

> 63:      * From the JavaDoc for java.lang.reflect.NullRestrictedType
> 64:      * "Instances of classes that implement this interface must implement
> 65:      * an equals() method that equates any two null rrestricted type instances that

`rrestricted`

test/langtools/tools/javac/nullability/NullRestrictionReflectiveTest.java line 2:

> 1: /*
> 2:  * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.

2026?

test/langtools/tools/javac/nullability/NullRestrictionReflectiveTest.java line 97:

> 95:     public void doWork() throws IOException {
> 96:         newCompilationTask()
> 97:                 .withOptions(List.of("--enable-preview", "--release", "26"))

should be 27, but in any case better not to wire a specific version

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

PR Review Comment: https://git.openjdk.org/valhalla/pull/1863#discussion_r2669351810
PR Review Comment: https://git.openjdk.org/valhalla/pull/1863#discussion_r2669356609
PR Review Comment: https://git.openjdk.org/valhalla/pull/1863#discussion_r2669357855
PR Review Comment: https://git.openjdk.org/valhalla/pull/1863#discussion_r2669363811
PR Review Comment: https://git.openjdk.org/valhalla/pull/1863#discussion_r2669385150
PR Review Comment: https://git.openjdk.org/valhalla/pull/1863#discussion_r2669391525


More information about the valhalla-dev mailing list