On Mon, 22 Sep 2025 17:08:20 GMT, Chen Liang <[email protected]> wrote:

>> Implementation changes for [JEP 500: Prepare to Make Final Mean 
>> Final](https://openjdk.org/jeps/500).
>> 
>> Field.set (and Lookup.unreflectSetter) are changed to allow/warn/debug/deny 
>> when mutating a final instance field. JFR event recorded if final field 
>> mutated. Spec updates to Field.set, Field.setAccessible and Module.addOpens 
>> to align with the proposal in the JEP.
>> 
>> HotSpot is updated to add support for the new command line options. To aid 
>> diagnosability, -Xcheck:jni reports a fatal error when a mutating a final 
>> field with JNI, and -Xlog:jni=debug can help identity when JNI code mutates 
>> finals. For now, JNI code is allowed to set the "write-protected" fields 
>> System.in/out/err, we can re-visit once we change the 
>> System.setIn/setOut/setErr methods to not use JNI (I prefer to keep this 
>> separate to this PR because there is a small startup regression to address 
>> when changing System.setXXX).
>> 
>> There are many new tests. A small number of existing tests are changed to 
>> run /othervm as reflectively opening a package isn't sufficient. Changing 
>> the tests to /othervm means that jtreg will launch the agent with the 
>> command line options to open the package.
>> 
>> Testing: tier1-6
>
> src/java.base/share/classes/java/lang/reflect/Field.java line 1461:
> 
>> 1459:         return Modifier.isFinal(modifiers)
>> 1460:                 && !Modifier.isStatic(modifiers)
>> 1461:                 && !clazz.isRecord()
> 
> This check cannot constant fold in the edge case where the declaring class 
> extends `java.lang.Record` but does not have a `Record` attribute. I have 
> seen such classes in proguard-stripped code.

If this were to become an issue then we could separate the isFinal check.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25115#discussion_r2369589705

Reply via email to