Skip to content

8388833: Fix JDWP spec w.r.t. setting static final fields and provide warnings about setting final fields - #32029

Open
plummercj wants to merge 3 commits into
openjdk:masterfrom
plummercj:8388833_setvalues
Open

8388833: Fix JDWP spec w.r.t. setting static final fields and provide warnings about setting final fields#32029
plummercj wants to merge 3 commits into
openjdk:masterfrom
plummercj:8388833_setvalues

Conversation

@plummercj

@plummercj plummercj commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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, 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.



Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change requires CSR request JDK-8389222 to be approved

Issues

  • JDK-8388833: Fix JDWP spec w.r.t. setting static final fields and provide warnings about setting final fields (Bug - P4)
  • JDK-8389222: Fix JDWP spec w.r.t. setting static final fields and provide warnings about setting final fields (CSR)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/32029/head:pull/32029
$ git checkout pull/32029

Update a local copy of the PR:
$ git checkout pull/32029
$ git pull https://git.openjdk.org/jdk.git pull/32029/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 32029

View PR using the GUI difftool:
$ git pr show -t 32029

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/32029.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Jul 23, 2026

Copy link
Copy Markdown

👋 Welcome back cjplummer! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Jul 23, 2026

Copy link
Copy Markdown

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk Bot changed the title 8388833 8388833: Fix JDWP spec w.r.t. setting static final fields and provide warnings about setting final fields Jul 23, 2026
@openjdk openjdk Bot added serviceability serviceability-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jul 23, 2026
@openjdk

openjdk Bot commented Jul 23, 2026

Copy link
Copy Markdown

@plummercj The following labels will be automatically applied to this pull request:

  • core-libs
  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@plummercj

Copy link
Copy Markdown
Contributor Author

/label remove core-libs

@openjdk openjdk Bot removed the core-libs core-libs-dev@openjdk.org label Jul 23, 2026
@openjdk

openjdk Bot commented Jul 23, 2026

Copy link
Copy Markdown

@plummercj
The core-libs label was successfully removed.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Jul 23, 2026
@mlbridge

mlbridge Bot commented Jul 23, 2026

Copy link
Copy Markdown

Webrevs

"Access control is not enforced; for example, the values of private "
"fields can be set. "
"fields can be set. Setting a final instance field is permitted but may "
"result in an unexpected exception or a fatal crash. "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec update looks good (and consistent with JNI as you note).

@plummercj

Copy link
Copy Markdown
Contributor Author

/csr

@openjdk openjdk Bot added the csr Pull request needs approved CSR before integration label Jul 28, 2026
@openjdk

openjdk Bot commented Jul 28, 2026

Copy link
Copy Markdown

@plummercj has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@plummercj please create a CSR request for issue JDK-8388833 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

csr Pull request needs approved CSR before integration rfr Pull request is ready for review serviceability serviceability-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

2 participants