`Copies.Copy.equals` and `Copies.Copy.hashCode` in `Copies.java` disagree, breaking the Java equals/hashCode contract
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Java
- Estrellas
- 22
- Forks
- 14
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de zold-io/java-api
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
bug help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
bug pdd
Dificultad 2/5 Menos de una hora Aptitud para principiantes 72/100
-
bug pdd
Dificultad 2/5 Menos de una hora Aptitud para principiantes 68/100
Todos los issues de zold-io/java-api
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
infinispan/infinispan#18150 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
opensearch-project/k-NN#3597 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100