[ 
https://issues.apache.org/jira/browse/LANG-959?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17606014#comment-17606014
 ] 

Zili Chen commented on LANG-959:
--------------------------------

Perhaps we can close this issue as {{removeFinalModifier}} also gets deprecated 
after JDK12:


{code:java}
As of Java 12, we can no longer drop the {@code final} modifier, thus rendering 
this method obsolete. The JDK discussion about this change can be found here: 
https://mail.openjdk.java.net/pipermail/core-libs-dev/2018-November/056486.html
{code}

IIRC {{powermock-reflect}}'s {{WhiteBox}} can still workaround this restriction 
by force updating the field by {{Unsafe}}, but it may not be we will expect?


> FieldUtils write methods do not write to final fields.
> ------------------------------------------------------
>
>                 Key: LANG-959
>                 URL: https://issues.apache.org/jira/browse/LANG-959
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.reflect.*
>    Affects Versions: 3.2.1
>         Environment: Apache Maven 3.1.1 
> (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 11:22:22-0400)
> Maven home: C:\Java\apache-maven-3.1.1\bin\..
> Java version: 1.7.0_51, vendor: Oracle Corporation
> Java home: C:\Program Files\Java\jdk1.7.0_51\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
>            Reporter: Gary D. Gregory
>            Assignee: Gary D. Gregory
>            Priority: Major
>             Fix For: Review Patch
>
>         Attachments: LANG-959.diff
>
>
> I have a use case where I need to use reflection to set a public static final 
> Object.
> This does not work with our FieldUtils class because the "forceAccess" 
> argument is only used to deal with field visibility by calling 
> Field#setAccessible(boolean)
> Q1: Should "forceAccess" be expanded to remove the final modifier? Or:
> Q2: Should we add another boolean parameter "forceWrite" to remove the FINAL 
> modifier?
> I like Q1.
> Q3: The Accessible flag is NOT reset if changed after a write! I think it 
> should be. Thoughts?
> The attached patch implements this BUT does not fix failing tests that expect 
> writes to fail on final fields. I left the tests failing to show clearly 
> which ones fail so we can discuss if:
> - this fixes a bug, 
> - is an improvement acceptable for the next release
> - or breaks too much for the next release
> Discuss here or on the ML.
> Thank you.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to