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

Gary D. Gregory commented on LANG-1765:
---------------------------------------

Hello [~sustech-whl]

Your example reflects the behavior documented in the Javadoc in git master.

In 3.17.0, the Javadoc was not updated to document the behavior to match the 
code.

HTH.

> when using FieldUtils.readDeclaredStaticField throw a NullPointerException
> --------------------------------------------------------------------------
>
>                 Key: LANG-1765
>                 URL: https://issues.apache.org/jira/browse/LANG-1765
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.17.0
>            Reporter: Wang Hailong
>            Priority: Major
>
> The mimal test case is like that:
> {color:#cc7832}class {color}ChildClass
> { 
> static String fieldName{color:#cc7832};
> }{color}
>     @org.junit.jupiter.api.Test // Corrected annotation usage
>     public void testReadStaticFieldAcrossInheritance() throws Exception {
>         // Data Preparation
>         Class<?> cls = ChildClass.class;
>         Field field = cls.getDeclaredField("fieldName");
>         field.setAccessible(true);
>         // API Invocation
>         Object value = FieldUtils.readDeclaredStaticField(cls, "fieldName");  
>   }
> And it just throw a nullpointerException
> And I find out why it could happen:
> in the method : getDeclaredField
> try {
>             Field field = cls.getDeclaredField(fieldName);
>             if (!MemberUtils.isAccessible(field)) {
>                 if (!forceAccess) {
>                     return null;
>                 }
>                 field.setAccessible(true);
>             }
>   The method "MemberUtils.isAccessible(field)"  it can not recognize that I 
> have set the filed to be accessible by java reflection. So it just return 
> null and the it will throw a nullPointerException
>  
>  
>  



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

Reply via email to