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

Zhiqiang Zang commented on LANG-1499:
-------------------------------------

[~sebb] Thank you for your comments. Thank you for pointing out some 
inconsistency between Javadoc and code, which should be inspected, too. I want 
to share more findings such that this issue makes more sense.

equals() method should be able to return true when comparing two different 
classes sharing a common superclass, such as LinkedList and ArrayList. Actually 
Java built-in equals() method supports this case.

The code for EqualsBuilder.reflectionEquals() does check if one class is a 
superclass of the other but it simply returns false for all other cases, which 
is the cause of the issue.

[https://commons.apache.org/proper/commons-lang/xref/org/apache/commons/lang3/builder/EqualsBuilder.html#L522]

One potential fix could be to have another else if branch to check if two 
classes share a common superclass.

> Equals transitivity is violated in EqualsBuilder
> ------------------------------------------------
>
>                 Key: LANG-1499
>                 URL: https://issues.apache.org/jira/browse/LANG-1499
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.builder.*
>    Affects Versions: 3.9
>         Environment: Ubuntu 18.04
> JDK 1.8.0_221
> Commons Lang 3.9-RC2
> JUnit 5.4
>            Reporter: Zhiqiang Zang
>            Priority: Major
>              Labels: Equals(), EqualsBuilder, transitivity
>         Attachments: EqualsTransitivityTest.java
>
>
> EqualsBuilder.reflectionEquals() does not hold transitivity when comparing 
> two subclasses extending a common superclass. For example:
> Given that both class D and E are subclasses of class C, C == D and C == E 
> should imply D == E. However EqualsBuilder.reflectionEquals(D, E) returns 
> *false* when both EqualsBuilder.reflectionEquals(C, D) and 
> EqualsBuilder.reflectionEquals(C, E) return true.
> A junit test is provided as attachment.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to