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

Incorrect code if grandparent class overrides equals(Object) / hashCode() #13

Closed
chludwig-haufe opened this issue Jan 30, 2014 · 5 comments

Comments

@chludwig-haufe
Copy link

Hi,

the plugin adds calls super.equals(obj) and super.hashCode(), respctively, if the parent class has its own implementation of these methods (and the parent class is not java.lang.Object).

However, the plugin fails to call super.equals(obj) and super.hashCode() if these were overriden in a class further up in the hierarchy. The code in https://dl.dropboxusercontent.com/u/1675887/OverridenEqualsHashCode.zip demonstrates this issue:

  • Class A has two subclasses B1 and B2. B1 has a subclass C1, and B2 has a subclass C2.
  • A and B1 do override equals(Object) and hashCode(); B2 does not.
  • The equals(Object) and hashCode() implementations generated for C1 are correct, they call the overridden implementations, respectively.
  • The code generated for C2 does not call super.equals(obj) and super.hashCode(), respectively, even though its equality does also depend on A's notion of equality.

Regards
Christoph

@mjedynak
Copy link
Owner

mjedynak commented Feb 4, 2014

Fixed in v. 1.0.9

@chludwig-haufe
Copy link
Author

Thanks for the prompt fix!

Regards,
Christoph

From: Michal Jedynak [mailto:notifications@github.com]
Sent: Tuesday, February 04, 2014 9:13 PM
To: mjedynak/EqualsHashCodeDeluxeGenerator
Cc: Ludwig, Christoph
Subject: Re: [EqualsHashCodeDeluxeGenerator] Incorrect code if grandparent class overrides equals(Object) / hashCode() (#13)

Fixed in v. 1.0.9


Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-34101609.

@jruillier
Copy link

Thanks !

@vanhove
Copy link

vanhove commented Feb 19, 2014

It still generates a faulty equals method:
f (obj == null || getClass() != obj.getClass()) {

It doesn't use the instanceOf and it doesn't do super.equals() in the return statement

@mjedynak
Copy link
Owner

mjedynak commented Mar 8, 2014

The 'equals' method is generated according to http://www.technofundo.com/tech/java/equalhash.html, which describes why '(obj == null || getClass() != obj.getClass())' should be used instead of 'instanceOf'.
It also calls 'super.equals()' if it was overridden in inheritance hierarchy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants