@Data needs a warning when either equals() or hashCode() is already implemented #548

Closed
lombokissues opened this Issue Jul 14, 2015 · 5 comments

Projects

None yet

1 participant

@lombokissues
Collaborator

Migrated from Google Code (issue 513)

@lombokissues
Collaborator

👤 ericlef   🕗 May 02, 2013 at 15:27 UTC

I was in the process of Lombokifying a bean, step by step. This meant removing the hashCode(), leaving equals() as it was, and counting on Lombok to generate an appropriate hashCode().
This made tests fail obscurely, and it took us a few hours to figure out that hashCode() was not being generated, as equals() was still present.

It only became clear when, on a whim, we add @ EqualsAndHashCode to our class. This gave us an appropriate warning ("Not generating equals, hashCode and canEquals: A method with one of those names already exists. (Either all or none of these methods will be generated).")

I would like to see the same warning on @ Data.

Side note: I tried using delombok to figure out the issue. However, in order to make my class compile without the whole classpath, I removed equals() temporarily. I saw the code generated by delombok, so I was quite sure that nothing was wrong... Of course, I immediately restore equals() and didn't make the connection with the problem at all. ;-)

@lombokissues
Collaborator

👤 reinierz   🕗 May 06, 2013 at 18:59 UTC

This isn't a lombok bug, it's a bug in our specs, because this is dumb but specified behaviour.

We are going to re-spec the behaviour to this new rule: If using @ Data and you have only one of the pair of equals/hashCode methods implemented, you get a warning. If you have 0 of the 2, they get added. If you have both, they aren't, and you get no warning.

That's how it works now except for the weird '1 is there but the other one is missing' case that you ran into.

@lombokissues
Collaborator

👤 reinierz   🕗 May 06, 2013 at 20:09 UTC

Fixed; will be in next release.

@lombokissues lombokissues removed the accepted label Jul 14, 2015
@lombokissues
Collaborator

👤 ericlef   🕗 May 06, 2013 at 22:20 UTC

Thanks!

@lombokissues
Collaborator

End of migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment