[
https://issues.apache.org/jira/browse/LANG-965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14110652#comment-14110652
]
Benedikt Ritter commented on LANG-965:
--------------------------------------
Hello André,
bq. Therefore it needs to be restored in the above mentioned read/write methods
separately.
Okay, makes sense. Maybe we should add a comment in JavaDoc, that users have to
take care of restoring accessibility when using {{getField()}}...
bq. The original tests failed after the "accessibility leak" has been fixed.
Nice :-) However I think it would be better to use {{FieldUtils.readField()}}
to check if the field has been set correctly and to assert that the field is
not accessible after the call to {{writeField()}}. WDYT?
Another thing that caught my eye:
{code:java}
// restore accessibility if previously changed
if (forceAccess && !Modifier.isPublic(field.getModifiers()))
field.setAccessible(false);
{code}
1. missing curly brackets ;-) We use curly brackets even for one line blocks.
2. I'm not sure whether {{!Modifier.isPublic(field.getModifiers()))}} really is
the same as {{Field.isAccessible() == false}}. Reading through the JavaDoc of
{{Field.setAccessible(boolean)}} sounds like it is a difference. But I don't
know. It think it would be better to get the field via {{getField(cls,
fieldName, false)}}, store the accessibility, do all neccessary operations and
then restore the original state. This way you only need to restore the
accessibility once.
> FieldUtils methods leak accessible flags
> ----------------------------------------
>
> Key: LANG-965
> URL: https://issues.apache.org/jira/browse/LANG-965
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.reflect.*
> Affects Versions: 3.1, 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 Gregory
> Assignee: Benedikt Ritter
> Fix For: Review Patch
>
> Attachments: commons-lang-965.patch
>
>
> When various FieldUtils methods are called the accessible is set to true but
> never reset to false. This is side-effect should be cleaned up.
> This makes a mess of the object model which represents the class meta data.
--
This message was sent by Atlassian JIRA
(v6.2#6252)