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

Abierto
#136 1 comentario 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
java
Área
api, backend

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

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.

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

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de zold-io/java-api

Todos los issues de zold-io/java-api

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.