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

Equals not tested with object of other type #47

Closed
GoogleCodeExporter opened this issue Mar 29, 2015 · 3 comments
Closed

Equals not tested with object of other type #47

GoogleCodeExporter opened this issue Mar 29, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem? 1. Assume following equals implementation

@Override public boolean equals(final Object otherObj) { if ((otherObj == null) 
|| !(otherObj instanceof DiscussionEntry)) { return false; }

if (otherObj == this) { return true; }

final DiscussionEntry other = (DiscussionEntry) otherObj; return new 
EqualsBuilder().append( getCreatedOn(), other.getCreatedOn()) 
.append(getCreatedBy(), other.getCreatedBy()) .isEquals(); }

2. In code coverage you will see that the instanceof never yields false.

What is the expected output? What do you see instead?

Expected: equals to be tested with an object of another type. Actual: The 
equals is not tested with an object of another type.

What version of the product are you using? On what operating system?

1.0.1 on Windows XP with TestNG on eclipse and Cobertura coverage through 
Jenkins.

Original issue reported on code.google.com by stijn.ge...@gmail.com on 24 Jun 2011 at 11:36

@GoogleCodeExporter
Copy link
Author

You're right. Don't know how I haven't noticed this before :).

I'll fix it in the next release.

Original comment by jan.ouw...@gmail.com on 28 Jun 2011 at 6:33

  • Changed state: Accepted
  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

No worries, great project for the rest! Tx.

Original comment by stijn.ge...@gmail.com on 28 Jun 2011 at 6:42

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Added a check for this issue. As of next version, EqualsVerifier will complain 
if it detects a missing instanceof or getClass() check.

Original comment by jan.ouw...@gmail.com on 7 Aug 2011 at 8:47

  • Changed state: Fixed
  • Added labels: ****
  • Removed labels: ****

jqno pushed a commit that referenced this issue Aug 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant