JDK-8280798 : com.sun.jdi.ObjectReference::setValue spec should prohibit any final field modification
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-01-27
  • Updated: 2022-12-08
  • Resolved: 2022-12-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 20
20 b27Fixed
Related Reports
CSR :  
Relates :  
Description
com.sun.jdi.ObjectReference::setValue spec says:
--------
Sets the value of a given instance or static field in this object. The Field must be valid for this ObjectReference; that is, it must be from the mirrored object's class or a superclass of that class. If static, the field must not be final.
-------
"If static" is confusing here.
The method throws  IllegalArgumentException ("Cannot set value of final field") for both static and instance final fields.


Comments
Changeset: 2821fa98 Author: Alex Menkov <amenkov@openjdk.org> Date: 2022-12-02 20:16:51 +0000 URL: https://git.openjdk.org/jdk/commit/2821fa9883cc9687b53e3bb5655732a614cff8fc
02-12-2022

JDI cannot produce any warnings, so each debugger would need to check for this specific case and produce the warning. I'd say ability to modify final instance fields and inability to change final statics is JVM implementation details. To me the main reason to update the spec instead of fix of implement to allow modify instance final fields is not safety - it may cause unpredictable effects in other part of debugee. https://bugs.eclipse.org/bugs/show_bug.cgi?id=577564 describes a real case when change of final field caused "impossible" application behavior and this took a lot of time to understand than can happen.
22-11-2022

I would have expected that a debugger should, and needs to, be able to modify final fields - naturally with caveats/warnings. I think the restriction on "static final" is more to do with compile-time constants than anything as the debugger could not propagate such a change.
22-11-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/11279 Date: 2022-11-21 22:58:54 +0000
21-11-2022

Discovered that Eclipse JDI implementation allows to modify final variables: https://bugs.eclipse.org/bugs/show_bug.cgi?id=94223 But as this can be quite unsafe the debugger shows warning dialog before changing final value: https://bugs.eclipse.org/bugs/show_bug.cgi?id=577564
14-02-2022