Skip to content

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

Closed
@yuqi1129

Description

@yuqi1129

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

Metadata

Metadata

Assignees

Labels

0.9.0Release v0.9.0bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is needed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions