Copilot commented on code in PR #13416:
URL: https://github.com/apache/gravitino/pull/13416#discussion_r4069204976
##########
core/src/main/java/org/apache/gravitino/meta/TableEntity.java:
##########
@@ -200,19 +200,25 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
- return Objects.hashCode(
- id,
- name,
- auditInfo,
- columns,
- namespace,
- properties,
- Arrays.hashCode(partitioning),
- Arrays.hashCode(sortOrders),
- distribution,
- distribution,
- Arrays.hashCode(indexes),
- comment);
+ // columns are compared as an unordered collection in equals, so their hash
+ // contribution must not depend on element order either.
+ int hash =
+ Objects.hashCode(
+ id,
+ name,
+ auditInfo,
+ namespace,
+ properties,
+ Arrays.hashCode(partitioning),
+ Arrays.hashCode(sortOrders),
+ distribution,
+ Arrays.hashCode(indexes),
+ comment);
+ return 31 * hash + unorderedHashCode(columns);
+ }
+
+ private static int unorderedHashCode(List<?> list) {
+ return list == null ? 0 : list.stream().mapToInt(Object::hashCode).sum();
Review Comment:
`withColumns` keeps the supplied list unchanged and entity validation only
checks that it is a `List`, so a built table can contain a null column.
`CollectionUtils.isEqualCollection` can compare matching null elements as
equal, but `Object::hashCode` dereferences them, causing
`TableEntity.hashCode()` to throw for an otherwise constructible table. Make
the element contribution null-safe (or reject null elements consistently when
building the entity).
--
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]