RFR: 8280798: com.sun.jdi.ObjectReference::setValue spec should prohibit any final field modification

Chris Plummer cjplummer at openjdk.org
Tue Nov 22 22:36:29 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

https://docs.oracle.com/en/java/javase/18/docs/api/java.base/java/lang/reflect/Field.html#set(java.lang.Object,java.lang.Object)

It is allowed, for the most part, but with the warning: 

`
Setting a final field in this way is meaningful only during deserialization or reconstruction of instances of classes with blank final fields, before they are made available for access by other parts of a program. Use in any other context may have unpredictable effects, including cases in which other parts of a program continue to use the original value of this field.`

In [JDK-8280798](https://bugs.openjdk.org/browse/JDK-8280798) Alex has documented a use case that shows the dangers of allowing this:

https://bugs.openjdk.org/browse/JDK-8280798?focusedCommentId=14539651&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14539651

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

PR: https://git.openjdk.org/jdk/pull/11279


More information about the serviceability-dev mailing list