Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] Possible error in the equals method for collection #6641

Open
yuqi1129 opened this issue Mar 8, 2025 · 1 comment · May be fixed by #6644
Open

[Bug report] Possible error in the equals method for collection #6641

yuqi1129 opened this issue Mar 8, 2025 · 1 comment · May be fixed by #6644
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@yuqi1129
Copy link
Contributor

yuqi1129 commented Mar 8, 2025

Version

main branch

Describe what's wrong

The following test will fail due to the fact that for Objects.equals, a collection with the same elements but different sequence are not equal.

    List<String> tags = Lists.newArrayList("tag1", "tag2");
    List<String> tagValues = Lists.newArrayList("tag2", "tag1");
    Assertions.assertTrue(Objects.equals(tags, tagValues));

There are a lot of method equals using Objects.equals to compare collection.

public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof SecurableObject)) {
return false;
}
SecurableObject otherSecurableObject = (SecurableObject) other;
return super.equals(other) && Objects.equals(privileges, otherSecurableObject.privileges());

public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof UserEntity)) return false;
UserEntity that = (UserEntity) o;
return Objects.equals(id, that.id)
&& Objects.equals(name, that.name)
&& Objects.equals(namespace, that.namespace)
&& Objects.equals(auditInfo, that.auditInfo)
&& Objects.equals(roleNames, that.roleNames)
&& Objects.equals(roleIds, that.roleIds);
}

We can use apache common-collection4 CollectionUtils.isEqualCollection to replace Object.equals for collection value.

Error message and/or stacktrace

Please see above

How to reproduce

please see above

Additional context

No response

@yuqi1129 yuqi1129 added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Mar 8, 2025
@sunxiaojian
Copy link
Contributor

@yuqi1129 please assign it to me, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants