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

Gary D. Gregory edited comment on LANG-1765 at 3/21/25 1:43 PM:
----------------------------------------------------------------

Hello [~sustech-whl]

Note that the title of this ticket does not match your example but that should 
not matter for the underlying issue. I'll update the title.

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.


was (Author: garydgregory):
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.

> Fix Javadoc for FieldUtils.readDeclaredStaticField()
> ----------------------------------------------------
>
>                 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
>             Fix For: 3.18.0
>
>
> 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