On Sun, 14 Nov 2021 19:54:50 GMT, Martin Grigorov <d...@openjdk.java.net> wrote:

>> Mandy Chung has updated the pull request with a new target base due to a 
>> merge or a rebase. The pull request now contains 43 commits:
>> 
>>  - fix copyright header and typo
>>  - improve documentation of AccessorUtils
>>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
>> reimplement-method-invoke
>>  - Fall back to the VM native reflection support if method handle cannot be 
>> created
>>  - fix bug id in test
>>  - Merge
>>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
>> reimplement-method-invoke
>>  - Merge branch 'master' of https://github.com/openjdk/jdk into 
>> reimplement-method-invoke
>>  - Separate paramFlgas into paramCount and flags fields
>>  - Minor cleanup.  Improve javadoc in CallerSensitiveAdapter
>>  - ... and 33 more: 
>> https://git.openjdk.java.net/jdk/compare/9a3e9542...46cb306b
>
> Thank you for the comments!
> There is no need to be harsh though! We just made use of old Reflection APIs. 
> They were working for many years and according to StackOverflow Apache Wicket 
> is not the only one doing this!
> In our case it is done in a test case, so it is easy to rework it. 
> 
>> Are there many Wicket tests trying to modify static field fields?
> 
> No! We have just one failing test with JDK 18 b23.
> 
> In someone else's case it might be needed to "hack" a third party library.
> 
> As a good citizen I'm reporting it back to you!

@martin-g I wasn't making any judgement. To qualify why this is not something I 
think anyone should do: poking into reflection internals to make a static final 
field mutable opens you up to situations where some readers still see the old 
value. An optimizing compiler (JIT or AOT) may treat the value as constant and 
propagates it. Future JVM features might decide to be even more aggressive, and 
trust these fields even more completely. While it's unspecified what should 
happen after overwriting a static final field with reflection, it does work if 
you're lucky. The one-off use in Wicket for a test seem benign enough. 

Alan: changing `Field.modifiers` still works, but dropping the final modifier 
is not enough for this to work in the new impl. It won't be hard to adapt to 
the new world. Users who relies on this today could for example opt-out of the 
new MH-based impl using `-Djdk.reflect.useDirectMethodHandle=false` and get the 
old behavior. I've checked using a minimal reproducer I extracted from the 
Wicket sources that this works.

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

PR: https://git.openjdk.java.net/jdk/pull/5027

Reply via email to