You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2026/05/17 11:20:00 UTC

[jira] [Resolved] (LANG-1825) EqualsBuilder.reflectionAppend tries to set visibility on excluded fields

     [ https://issues.apache.org/jira/browse/LANG-1825?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory resolved LANG-1825.
-----------------------------------
    Fix Version/s: 3.21.0
       Resolution: Fixed

[~dskiles]

Thank you for your report.

This is now addressed in git master and snapshot builds in https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-lang3/3.21.0-SNAPSHOT/

Please verify your use and close this ticket if appropriate.


> EqualsBuilder.reflectionAppend tries to set visibility on excluded fields
> -------------------------------------------------------------------------
>
>                 Key: LANG-1825
>                 URL: https://issues.apache.org/jira/browse/LANG-1825
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.builder.*
>    Affects Versions: 3.20.0
>            Reporter: Daniel Skiles
>            Assignee: Gary D. Gregory
>            Priority: Minor
>             Fix For: 3.21.0
>
>
> EqualsBuilder has a method named setExcludeFields, which "Sets field names to be excluded by reflection tests".  When used in conjunction with reflectionAppend, it will fail if the objects under comparison contain a reference to hidden JVM components.
> This is because the private reflectionAppend method sets visibility on all declared fields _before_ checking if the field is excluded or not.
> You can reproduce this behavior with this code:
>  
> {color:#7f0055}public{color}{color:#000000} {color}{color:#7f0055}static{color}{color:#000000} {color}{color:#7f0055}final{color}{color:#000000} {color}{color:#7f0055}void{color}{color:#000000} main({color}{color:#7f0055}final{color}{color:#000000} String... {color}{color:#6a3e3e}args{color}{color:#000000}) {color}{color:#7f0055}throws{color}{color:#000000} Exception {{color}
> {color:#7f0055}    final{color}{color:#000000} ArrayList<String> {color}{color:#6a3e3e}lhs{color}{color:#000000} = {color}{color:#7f0055}new{color}{color:#000000} ArrayList<>();{color}
> {color:#7f0055}    final{color}{color:#000000} ArrayList<String> {color}{color:#6a3e3e}rhs{color}{color:#000000} = {color}{color:#7f0055}new{color}{color:#000000} ArrayList<>();{color}
> {color:#6a3e3e}    lhs{color}{color:#000000}.add({color}{color:#2a00ff}"test"{color}{color:#000000});{color}
> {color:#7f0055}    new{color}{color:#000000} EqualsBuilder(){color}
> {color:#000000}        .setExcludeFields({color}{color:#2a00ff}"serialVersionUID"{color}{color:#000000}){color}
> {color:#000000}        .setTestRecursive({color}{color:#7f0055}true{color}{color:#000000}){color}
> {color:#000000}        .reflectionAppend({color}{color:#6a3e3e}lhs{color}{color:#000000}, {color}{color:#6a3e3e}rhs{color}{color:#000000}){color}
> {color:#000000}        .isEquals();{color}
> {color:#000000} }{color}
>  
> {color:#000000}It looks like it would be safe to move the AccessibleObject{color}.{color:#000000}setAccessible{color}({color:#6a3e3e}fields{color}, {color:#7f0055}true{color}); call inside the if block.



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