From JDK12 it is not possible to drop 'final' modifier
andrewluotechnologies at outlook.com
Wed Nov 7 18:57:19 UTC 2018
Also, you might want to take a look at JLS 13.4.9 "final Fields and Constants". Primitive static final constants can be folded at compile time, so even if you were able to change it at runtime, it wouldn't have any effect...
From: core-libs-dev <core-libs-dev-bounces at openjdk.java.net> On Behalf Of Alan Bateman
Sent: Wednesday, November 7, 2018 10:11 AM
To: Enrico Olivelli <eolivelli at gmail.com>; core-libs-dev at openjdk.java.net
Subject: Re: From JDK12 it is not possible to drop 'final' modifier
On 07/11/2018 16:42, Enrico Olivelli wrote:
> I am investigating this case about PowerMock, which is not able to
> remove the 'final' modifier from a Field
> Is there any suggested alternate way to remove such modifier ?
> I understand clearly that it is against how the JVM works and I really
> appreciate this "change", but this is blocking tests of several
> The only work-around I see is to not use "final" modifier for things
> that aren't really "final", but for instance my case is that "in
> production" I want the field to be treaded as "final" (in particular
> "final static" initialized with System Properties) but in unit tests I
> would like to be able to change the value without spawning a new JVM.
> I did not find any JIRA about this behavioral change, do you have any pointer ?
> If this is the direction (and I totally support it) I will be fine and
> adapt to the new rules.
Right, there's no supported way to change static final fields. Have you looked into the java agent dropping the final modifier at class load time?
More information about the core-libs-dev