RFR: 8280798: com.sun.jdi.ObjectReference::setValue spec should prohibit any final field modification
Alan Bateman
alanb at openjdk.org
Wed Nov 23 08:09:28 UTC 2022
On Mon, 21 Nov 2022 22:58:54 GMT, Alex Menkov <amenkov at openjdk.org> wrote:
> com.sun.jdi.ObjectReference::setValue spec says that final static fields cannot be modified, but openjdk implementation throws IllegalArgumentException for any final fields (static or instance).
>
> The fix updates the spec to prohibit any final field modification
> CSR: JDK-8281652
I dug into the pre-OpenJDK history as most of the action on this was in 1999.
In 1999, ObjectReference.setValue's docs changed from "The field must not be final" to "If static, the field must not be final". The exception message started out as "Cannot set value of final field" and changed to "Cannot set value of static final field".
jjh re-visited it in 2005 via JDK-623152 where he changed the exception message to "Cannot set value of final field".
I don't think the ancient history sheds much more light on the original intent. I suspect the original intent was to disallow setValue only static final fields. That would have aligned with Field.set + setAccessible(true) at the time.
In general I think the JDK is on the path to a world where "final means final". We see this with final fields on hidden classes and fields in records. So the proposal to change the JDI spec may be too bad but it require reaching out to IDE maintainers. Eclipse have their own JDI implementation. VS.Code uses the Eclipse JDI implementation. IntelliJ maintain a fork of JDI. So while the JDK's implementation of JDI has disallowed setting of all final fields for 20+ years, this is not the JDI implementation that is used by at least two of the main stream IDEs.
-------------
PR: https://git.openjdk.org/jdk/pull/11279
More information about the serviceability-dev
mailing list