On Mon, 22 Jun 2026 14:50:06 GMT, Chen Liang <[email protected]> wrote:

>> getstatic is specified/implement to throw ISE if a strictly-initialized 
>> static field is unset.  The reflection APIs are implemented to do the same 
>> but it doesn't surface in the API docs.
>> 
>> Field.getXXX is updated to specify the exception. Each getXXX method already 
>> specifies EIIE so it doesn't look out of place, and seems preferable to 
>> putting in the class description of isStrictInit. Doing the equivalent in 
>> MH/VH would add a lot of clutter so instead factory methods that produce a 
>> MH/VH to read a static field are updated. These methods already specify that 
>> they may provoke the field's class to be initialized so an additional 
>> sentence on invoking/operating-on while initializing the class doesn't look 
>> out of place.
>> 
>> StrictInitializingTest tests MH/VH access to a field that is unset but we 
>> don't seem to have tests for Field. Adding a simple test for Field.get and 
>> the MH/VH produced from a Field, and another test for FIeld.isStrictInit so 
>> its behavior when preview features are disabled and enabled is tested.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/java.base/share/classes/java/lang/reflect/Field.java line 286:
> 
>> 284:     /**
>> 285:      * Returns {@code true} if this field is a strictly-initialized 
>> field;
>> 286:      * returns {@code false} otherwise.
> 
> Related to previous preview label discussion with Jaikiran, I think we might 
> indicate for all reflective preview APIs what their non-preview fallback is.
> 
> For instance, a non-preview user sees this new ISE block, click on 
> "strictly-initialized", and reads this definition. That user has no idea how 
> a preexisting field appears in non-preview.
> 
> If we add something like "no field is strictly-initialized if preview 
> features are not enabled", users can see the ISE won't be thrown more easily.

Fair point, this one is a reflective preview API so frameworks/libraries can 
get a head start. I've expanded the wording.

(With preview APIs to date it seems like that framework maintainers are using 
reflection to access rather than compiling and have static references to the 
preview APIs. Probably compiling to an older release. At least 
"reflective=true" communicates the intent.)

> test/jdk/java/lang/reflect/Field/IsStrictInitTest.java line 26:
> 
>> 24: /*
>> 25:  * @test
>> 26:  * @summary Test Field.isStrictInit with fields that have 
>> ACC_STRICT_INIT set and not set
> 
> I think the summary should indicate the ACC_STRICT_INIT is classfile version 
> sensitive and ignored for older majors even when the bit is set in class 
> files. Like "ACC_STRICT_INIT should not be recognized in older class files"?

Okay, I'll see if I can improve the `@summary` line to make this clearer.

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

PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2572#discussion_r3459254684
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2572#discussion_r3461640262

Reply via email to