Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctness: Overriding equals, but not hashCode #344

Open
michaeldiamant opened this issue Jul 6, 2022 · 1 comment
Open

Correctness: Overriding equals, but not hashCode #344

michaeldiamant opened this issue Jul 6, 2022 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers Team Lamprey

Comments

@michaeldiamant
Copy link
Contributor

michaeldiamant commented Jul 6, 2022

Subject of the issue

While working on #340 (comment), I observed numerous instances where equals is overwritten, but not hashCode.

The status quo breaks hashCode's contract as discussed in https://stackoverflow.com/questions/2265503/why-do-i-need-to-override-the-equals-and-hashcode-methods-in-java.

Your environment

N/A

Steps to reproduce

N/A

Expected behaviour

There's at least 2 solutions:

  • Immediately - Consistently override hashCode and equals. Prefer using an IDE-generated implementation.
  • Longer term - Upgrade to >= JDK 16 and replace class definitions with records (https://docs.oracle.com/en/java/javase/16/language/records.html). Among other benefits, records obviate the need to manage equals and hashCode implementations.

Actual behaviour

N/A

Acceptance Criteria

  1. Updating hand written code to implement both functions.
  2. Update code generator to generate hashCode along with equals, then regenerate the code.
@michaeldiamant michaeldiamant added the new-bug Bug report that needs triage label Jul 6, 2022
@winder winder added the good first issue Good for newcomers label May 23, 2023
@algoanne algoanne added bug Something isn't working good first issue Good for newcomers and removed good first issue Good for newcomers new-bug Bug report that needs triage labels May 23, 2023
@winder
Copy link
Contributor

winder commented May 23, 2023

For the good first issue, implementing the first part of this would be helpful:

  1. Updating hand written code to implement both functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Team Lamprey
Projects
None yet
Development

No branches or pull requests

3 participants