`Copies.Copy.equals` and `Copies.Copy.hashCode` in `Copies.java` disagree, breaking the Java equals/hashCode contract
まだ誰も着手していません。
評価
調査の方向性
Read src/main/java/io/zold/api/Copies.java around lines 112-125, starting with Copy.compareTo, equals, and hashCode. Determine from the surrounding Copy usage whether identity is based on the wallet or score, then align the methods and verify that equal Copy instances produce equal hash codes in hash-based collections.
索引モデルが issue の本文から書いたものです。
説明
Copies.Copy.equals(Object) in src/main/java/io/zold/api/Copies.java lines 117-120 declares two Copy instances equal when this.compareTo((Copy) obj) == 0, and compareTo at lines 112-114 compares the two copies by their score(). The neighbouring hashCode() at lines 123-125, however, returns this.wlt.hashCode(), derived from the wallet object rather than the score.
The two definitions are not aligned, so two Copy instances that carry different wallets but the same summed score satisfy a.equals(b) == true while a.hashCode() != b.hashCode(). That contradicts the contract documented on java.lang.Object.hashCode, which requires equal objects to return equal hash codes, and breaks any HashMap, HashSet, or Hashtable that stores Copy values, since the bucket lookup uses the hash and never reaches the equals check.
The smallest fix is to derive both methods from the same field. Either replace the body of hashCode() with this.score().hashCode() so it tracks the same projection as equals, or rewrite equals to compare wallets so it tracks the same projection as hashCode. The choice depends on whether Copy identity is meant to be the wallet or the score it ranks by.
- 主要言語
- Java
- スター
- 22
- フォーク
- 14
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
zold-io/java-api のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
bug help wanted
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
bug pdd
難易度 2/5 1時間未満 初心者へのやさしさ 72/100
-
bug pdd
難易度 2/5 1時間未満 初心者へのやさしさ 68/100
zold-io/java-api の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
infinispan/infinispan#18150 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
opensearch-project/k-NN#3597 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100