Copilot commented on code in PR #13410:
URL: https://github.com/apache/gravitino/pull/13410#discussion_r4069188421
##########
core/src/main/java/org/apache/gravitino/meta/UserEntity.java:
##########
@@ -172,13 +172,22 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
- return Objects.hash(id, name, auditInfo, roleNames, roleIds);
+ // roleNames/roleIds are compared as unordered collections in equals, so
their
+ // hash contribution must not depend on element order either.
+ int hash = Objects.hash(id, name, namespace, auditInfo);
+ hash = 31 * hash + unorderedHashCode(roleNames);
+ hash = 31 * hash + unorderedHashCode(roleIds);
+ return hash;
}
public static Builder builder() {
return new Builder();
}
+ private static int unorderedHashCode(List<?> list) {
+ return list == null ? 0 : list.stream().mapToInt(Object::hashCode).sum();
+ }
Review Comment:
`equals` delegates to `CollectionUtils.isEqualCollection`, which supports
collections containing null elements, and the builder does not reject null list
entries. In that valid case this method throws `NullPointerException` from
`Object::hashCode`, whereas the previous list hash code handled nulls. Use a
null-safe element hash (for example, `Objects.hashCode`) so `hashCode()`
remains total for entities accepted by the builder.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]