`Copies.Copy.equals` and `Copies.Copy.hashCode` in `Copies.java` disagree, breaking the Java equals/hashCode contract

オープン
#136 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
java
領域
api, backend

調査の方向性

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 の本文から書いたものです。

説明

bug good first 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 はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

zold-io/java-api のほかの issue

zold-io/java-api の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。