Lang 1696 equals builder collections equals delegate#1615
Lang 1696 equals builder collections equals delegate#1615ShreyanshRaj22 wants to merge 2 commits intoapache:masterfrom
Conversation
…lementations in reflectionEquals
|
-1 for now: This may break existing applications that rely on reflection, since they asked for reflection to be used in the first place. To see why, rebase on git master and run I don't think we should start down the road of having special cases for this or that class, or it'll never end. I can also imagine an implementation of a collection or map that doesn't correctly implement equals(), breaking. I think it is safer for now to leave this reflection feature alone. |
|
Thanks for the feedback. I see how this change could break existing behavior relying on reflection comparison. I briefly considered implementing this as an optional flag-based toggle (as mentioned in the ticket), something like EqualsBuilder(obj1, obj2, shouldUseDefaultEquals), but that would likely introduce additional complexity for a fairly narrow use case. Given the backward compatibility concerns, I'll go ahead and close this PR. |
Description
This PR addresses LANG-1696 by improving the behavior of
EqualsBuilder.reflectionEqualswhen comparingCollectionandMapinstances. https://issues.apache.org/jira/browse/LANG-1696Instead of performing reflective field comparison on these types, the implementation now delegates directly to their
equalsmethods. SinceCollectionandMapalready define well-established equality semantics based on their contents, this produces more consistent and expected results when comparing different implementations containing the same elements.Changes
CollectionandMapinstances inreflectionEqualsand delegate comparison to theirequalsimplementations.HashSetandCollections.emptySet()).Compatibility
As noted in LANG-1696, this may change equality outcomes in cases where reflective comparison previously produced different results, but the new behavior aligns with the standard semantics of the Java Collections Framework.
Thanks for your contribution to Apache Commons! Your help is appreciated!
Before you push a pull request, review this list:
mvn; that'smvnon the command line by itself.