RFR: 8353835: Implement JEP 500: Prepare to Make Final Mean Final [v12]

Chen Liang liach at openjdk.org
Sat Nov 15 08:59:19 UTC 2025


On Fri, 14 Nov 2025 12:05:51 GMT, Alan Bateman <alanb at openjdk.org> 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 warning and -Xlog:jni=debug logs a message to help identity JNI code that mutates finals. For now, JNI code is allowed to set the "write-protected" fields System.in/out/err without a warning, 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
>
> Alan Bateman has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 59 commits:
> 
>  - Merge branch 'master' into JDK-8353835
>  - Cleanup
>  - More cleanup of Field.set API docs, including some restructure from Alex
>  - Cleanup
>  - Merge branch 'master' into JDK-8353835
>  - Update mutateFinals/modules test to exercise exports and opens cases
>  - Update Field.set spec to better align with setAccessible for public final field in public class in exported package
>  - Fix typo in java man page
>  - Add method to test if package exported
>  - Remove dup end body tag
>  - ... and 49 more: https://git.openjdk.org/jdk/compare/9eaa364a...7693e8fa

src/java.base/share/classes/java/lang/Module.java line 1032:

> 1030:      * Updates this module to export a package to another module.
> 1031:      *
> 1032:      * @apiNote Used addExports, Instrumentation::redefineModule, and --add-exports

Suggestion:

     * @apiNote Used by addExports, Instrumentation::redefineModule, and --add-exports

src/java.base/share/classes/java/lang/reflect/Field.java line 1621:

> 1619:     private String notAccessibleToCallerMessage(Class<?> caller, boolean unreflect) {
> 1620:         String exportOrOpen = Modifier.isPublic(modifiers)
> 1621:                 && Modifier.isPublic(clazz.getModifiers()) ? "exports" : "open";

Suggestion:

                && Modifier.isPublic(clazz.getModifiers()) ? "export" : "open";

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

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


More information about the core-libs-dev mailing list