[
https://issues.apache.org/jira/browse/HDDS-16353?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18110191#comment-18110191
]
Chia-Chuan Ho commented on HDDS-16353:
--------------------------------------
Thanks [~ivanandika] for the suggestion.
I explored EqualsVerifier locally. It is useful for checking many common
equals/hashCode issues, but this particular violation is subtle: equals()
compared nodeStatus.keySet(), while hashCode() used the entire nodeStatus map.
In a minimal reproduction, EqualsVerifier did not generate maps with the same
keys but different values, so it did not detect this violation automatically.
Pipeline also requires additional EqualsVerifier configuration for its non-null
and intentionally ignored fields.
Therefore, I think the targeted regression test is the most reliable coverage
for this specific bug. Broader adoption of EqualsVerifier may still be
valuable, but since it introduces a new test dependency and requires
class-specific configuration, perhaps we could evaluate it separately.
Please let me know what you think.
> Pipeline violates the equals and hashCode contract
> --------------------------------------------------
>
> Key: HDDS-16353
> URL: https://issues.apache.org/jira/browse/HDDS-16353
> Project: Apache Ozone
> Issue Type: Bug
> Components: common
> Reporter: Tsz-wo Sze
> Assignee: Chia-Chuan Ho
> Priority: Major
> Labels: pull-request-available
> Attachments: screenshot-1.png
>
>
> {code}
> //Pipeline.java
> @Override
> public boolean equals(Object o) {
> if (this == o) {
> return true;
> }
> if (o == null || getClass() != o.getClass()) {
> return false;
> }
> Pipeline that = (Pipeline) o;
> return new EqualsBuilder()
> .append(id, that.id)
> .append(replicationConfig, that.replicationConfig)
> .append(nodeStatus.keySet(), that.nodeStatus.keySet())
> .isEquals();
> }
> @Override
> public int hashCode() {
> return new HashCodeBuilder()
> .append(id)
> .append(replicationConfig.getReplicationType())
> .append(nodeStatus)
> .toHashCode();
> }
> {code}
> In the code above, hashCode() depends on nodeStatus but equals(..) depends
> only on nodeStatus.keySet(). When two pipelines p1 and p2 have the same
> nodeStatus.keySet() but different values,
> - p1.equals(p2) returns true
> - but p1.hashCode() != p2.hashCode()
> It violates [the contract of
> hashCode|https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--]:
> bq. If two objects are equal according to the equals(Object) method, then
> calling the hashCode method on each of the two objects must produce the same
> integer result.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]