From JDK12 it is not possible to drop 'final' modifier
Enrico Olivelli
eolivelli at gmail.com
Wed Nov 7 18:38:57 UTC 2018
Il mer 7 nov 2018, 19:10 Alan Bateman <Alan.Bateman at oracle.com> ha scritto:
> On 07/11/2018 16:42, Enrico Olivelli wrote:
> > Hi,
> > I am investigating this case about PowerMock, which is not able to
> > remove the 'final' modifier from a Field
> > https://github.com/powermock/powermock/issues/939
> >
> > 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
> > projects.
> >
> > 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?
>
Good idea. I will try.
Hopefully 'lazy final static' fields wil help in my case.
I will be back with my findings.
Thanky you
Enrico
>
> -Alan.
>
--
-- Enrico Olivelli
More information about the core-libs-dev
mailing list