`Copies.Copy.equals` and `Copies.Copy.hashCode` in `Copies.java` disagree, breaking the Java equals/hashCode contract
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Java
- Stelle
- 22
- Fork
- 14
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di zold-io/java-api
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
-
bug help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
bug pdd
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 72/100
-
bug pdd
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 68/100
Tutte le issue di zold-io/java-api
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
infinispan/infinispan#18150 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
untriaged
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100