On Mon, 15 Sep 2025 18:18:02 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 1439:
> 
>> 1437:         } else {
>> 1438:             // no java caller, only allowed if field is public in 
>> exported package
>> 1439:             if (!Reflection.verifyPublicMemberAccess(clazz, 
>> modifiers)) {
> 
> Is this sufficient? I know core libraries has APIs as public non-static final 
> fields, like java.lang.constant.DirectMethodHandleDesc$Kind.refKind. Don't 
> think they should be allowed to be modified by native code, for example.

If a JNI attached thread does an upcall to Field.set with no Java frames on the 
stack, then it is can mutate a public final field in a public class in an 
exported package when "illegal final field mutation" is allowed. If denied then 
IAE will be thrown.

> test/langtools/jdk/jshell/CompletionSuggestionTest.java line 35:
> 
>> 33:  * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
>> 34:  * @build KullaTesting TestingInputStream Compiler
>> 35:  * @run junit/othervm/timeout=480 CompletionSuggestionTest
> 
> Why does this need an update?

I mentioned this in the PR description because it is necessary to change a 
small number of tests ro run in /othervm mode. This is because jtreg 
reflectively opening a package isn't sufficient, it has to run the test with 
`--add-opens`.

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

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

Reply via email to