Daniel Skiles created LANG-1825:
-----------------------------------
Summary: 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
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
{color:#000000}{color:#000000}AccessibleObject{color}.{color:#000000}setAccessible{color}({color:#6a3e3e}fields{color},
{color:#7f0055}true{color});{color} call inside the if block.{color}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)