On Thu, 22 Jan 2026 23:44:52 GMT, Dan Smith <[email protected]> wrote:

> I want to confirm that this works on a non-preview class file, and that 
> nothing downstream is going to break. (Hard to prove that second point 
> definitively, but looking for some confirmation from a runtime expert.)

The annotation is currently parsed and processed without checking if the class 
file has a preview version number or not. Looks like an issue that can easily 
be fixed.

When a field is annotated with @NullRestricted, it is automatically marked as a 
null-free value field, which will trigger two actions later in the loading of 
the declaring class:
  1. the JVM will try to load the type of the field with circularity detection
  2. the JVM will check that the loaded type is a concrete value class
This is a remain of the previous lworld model, when strict fields didn't exist 
yet. This is not the behavior we want with null-restricted fields being strict. 
But this code is not part of JEP 401, so we haven't updated it yet.

For the JEP 401 preview, the simplest solution would be to simply reject or 
ignore the annotation when the class file hasn't a preview version number.

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

PR Comment: https://git.openjdk.org/valhalla/pull/1951#issuecomment-3792480908

Reply via email to