[
https://issues.apache.org/jira/browse/LANG-1696?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18063779#comment-18063779
]
Gary D. Gregory edited comment on LANG-1696 at 3/7/26 7:04 PM:
---------------------------------------------------------------
This may break existing applications that rely on reflection, since they asked
for reflection to be used in the first place. To see why, run
{{{}EqualsBuilderTest{}}}.
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.
was (Author: garydgregory):
This may break existing applications that rely on reflection, since they asked
for reflection to be used in the first place.
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.
> Add support of java collections to EqualsBuilder
> ------------------------------------------------
>
> Key: LANG-1696
> URL: https://issues.apache.org/jira/browse/LANG-1696
> Project: Commons Lang
> Issue Type: Improvement
> Components: lang.builder.*
> Reporter: Dmitry Katsubo
> Priority: Minor
>
> Provided that new {{HashSet<>().equals(Collections.emptySet())}} it would be
> great if {{EqualsBuilder}} also supports that. Currently it checks that
> [left/right classes are subclasses of each
> other|https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java#L499],
> however that does not hold for collections.
> Suggestion: if either left or right is {{Collection}} or {{Map}} then
> delegate equals to
> {code}
> public EqualsBuilder reflectionAppend(final Object lhs, final Object rhs) {
> if (!isEquals()) {
> return this;
> }
> if (lhs == rhs) {
> return this;
> }
> if (lhs == null || rhs == null) {
> setEquals(false);
> return this;
> }
> if (lhs instanceof Collection || rhs instanceof Collection || lhs
> instanceof Map || rhs instanceof Map) {
> setEquals(lhs.equals(rhs));
> return this;
> }
> ...
> {code}
> Likely this mode should be additionally controlled (switched on/off), as
> strictly speaking, it won't be a reflection tree walker starting from that
> field.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)