On Mon, 22 Jun 2026 13:24:22 GMT, Alan Bateman <[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). The test and spec changes looks good. 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. 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"? test/jdk/java/lang/reflect/Field/IsStrictInitTest.java line 63: > 61: .defineHiddenClass(classBytes, false) > 62: .lookupClass(); > 63: boolean expectStictInit = preview && strict; `expectStictInit` -> `expectStrictInit` typo ------------- PR Review: https://git.openjdk.org/valhalla/pull/2572#pullrequestreview-4545229523 PR Review Comment: https://git.openjdk.org/valhalla/pull/2572#discussion_r3453163506 PR Review Comment: https://git.openjdk.org/valhalla/pull/2572#discussion_r3460724703 PR Review Comment: https://git.openjdk.org/valhalla/pull/2572#discussion_r3460517579
