On Thu, 23 Jul 2026 16:50:05 GMT, Chris Plummer <[email protected]> wrote:

> The JDWP implementation (debug agent) allows the writing of static final 
> fields and instance final fields. This has always been the case since no 
> checks are made to prevent it, and JNI doesn't prevent it. The JDI spec 
> forbids the setting of final fields, and it has a check that will throw an 
> exception if attempted. However, it is important that we continue to allow 
> JDWP to write final fields because some debuggers allow for it at the JDI 
> level (protected by a click through warning). Although these debuggers are 
> not fully JDI compliant, there is no requirement that they be compliant, so 
> JDWP should continue to support this behavior. Much of this was discussed in 
> the PR for [JDK-8281652](https://bugs.openjdk.org/browse/JDK-8281652), which 
> clarified in the JDI spec that writing final fields was not allowed. This was 
> just a spec clarification. JDI already forbid the setting of final fields.
> 
> Having said all that, the JDWP spec for ClassType.SetValues says "Final 
> fields cannot be set." This is clearly wrong as it has always been allowed. 
> ObjectReference.SetValues says nothing about final fields, and also allows 
> them to be set.
> 
> This PR has two spec updates:
> - Get rid of the "Final fields cannot be set." text for ClassType.SetValues.
> - ObjectReference.SetValues and ReferenceType.SetValues should warn against 
> setting final fields by using language similar to JNI.
> 
> I've also updated two tests to test for setting both static final fields and 
> instance final fields. The tests (before my changes) verified the setting of 
> fields (not final) on the debuggee side. I tried the same with final fields 
> and ran into problems. The compiler inlines final primitives values, so 
> setting the final fields is not seen when the fields are referenced from java 
> (or at least this was the case with static final fields. I'm not positive 
> about instance final fields). So I added support for using GetValues to 
> verify the results rather than relying on the debuggee's view of the fields.
> 
> Testing in progress.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001.java 
line 179:

> 177:                             + "  " + TESTED_FINAL_CLASS_SIGNATURE);
> 178:                 long testedFinalClassID = 
> debugee.getReferenceTypeID(TESTED_FINAL_CLASS_SIGNATURE);
> 179:                 log.display("  got tested final classID: " + 
> testedClassID);

Q: Should it be `testedFinalClassID` instead of `testedClassID` at line 179?

test/hotspot/jtreg/vmTestbase/nsk/jdwp/ClassType/SetValues/setvalues001.java 
line 452:

> 450: 
> 451:     /**
> 452:      * Check confiramtion using JDWP ClassType.GetValues that the values 
> are changed.

Nit: Typo: s/confiramtion/confirmation/

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

PR Review Comment: https://git.openjdk.org/jdk/pull/32029#discussion_r3672263369
PR Review Comment: https://git.openjdk.org/jdk/pull/32029#discussion_r3672286672

Reply via email to