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

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

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

Comments

Projects
None yet
1 participant
@lombokissues
Collaborator

lombokissues commented Jul 14, 2015

Migrated from Google Code (issue 513)

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

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. ;-)

Collaborator

lombokissues commented Jul 14, 2015

👤 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

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

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.

Collaborator

lombokissues commented Jul 14, 2015

👤 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

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

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

Fixed; will be in next release.

Collaborator

lombokissues commented Jul 14, 2015

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

Fixed; will be in next release.

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

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

Thanks!

Collaborator

lombokissues commented Jul 14, 2015

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

Thanks!

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

End of migration

Collaborator

lombokissues commented Jul 14, 2015

End of migration

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