No Error Message explanation for Double: equals doesn't use Double.compare for field amount.

27 views
Skip to first unread message

Jason Erickson

unread,
Apr 10, 2011, 12:04:05 AM4/10/11
to equalsverifier
I get the following error message but the ErrorMessages wiki doesn't
explain it.

java.lang.AssertionError: Double: equals doesn't use Double.compare
for field amount.
For more information, go to: http://code.google.com/p/equalsverifier/wiki/ErrorMessages
at nl.jqno.equalsverifier.util.Assert.fail(Assert.java:96)
at
nl.jqno.equalsverifier.EqualsVerifier.handleError(EqualsVerifier.java:
332)
at nl.jqno.equalsverifier.EqualsVerifier.verify(EqualsVerifier.java:
312)
at
com.factorlab.opportunities.OpportunityTest.testEquals(OpportunityTest.java:
20)


Also, while it is technically correct that it doesn't use
Double.compare, in fact, the field is not participating in equals at
all. Is there a way to ask EqualsVerifier to skip fields for testing?

Jan Ouwens

unread,
Apr 10, 2011, 5:29:40 AM4/10/11
to equalsv...@googlegroups.com, Jason Erickson
Hi Jason,

I'll add an explanation to the wiki.

Regarding your question, EqualsVerifier should skip all fields that
aren't included in equals or hashCode automatically. Not sure why that
doesn't happen for you. Can you send me your class, or just your
equals and hashCode methods, so I can see what's going on?


Regards,
Jan

Jason Erickson

unread,
Apr 10, 2011, 12:54:53 PM4/10/11
to equalsv...@googlegroups.com
Actually, I was just using the Object.equals method at the time and it was complaining about Double.compare not being used.  After that, I overrode the equals and hashcode methods and did not include the double field and it worked as expected.  

So, my problem is fixed and it is probably an unusual use case to test the Object.equals method on your class, but I guess it is also a bug that it would give this error.

Here is the class that was causing the problems (before I added the equals and hashcode methods):
public class Opportunity implements HasLongId, HasZone, HasName {

private Zone zone;
private Long id;
private String name;
private Date closeDate;
private Double amount;
private Stage stage;



... getters and setters ...
}

That's it.  Very simple class.

Jan Ouwens

unread,
Apr 11, 2011, 2:36:17 PM4/11/11
to equalsv...@googlegroups.com, Jason Erickson
Hi Jason,

I've added an explanation to the wiki.
Regarding your class: normally, EqualsVerifier just passes when you
don't have an equals or hashCode method. However, because your class
happens to contain a Double, that suddenly took precendence. I've
added an issue in the issue tracker (
http://code.google.com/p/equalsverifier/issues/detail?id=44 ) to
resolve this one.


Regards,
Jan

Reply all
Reply to author
Forward
0 new messages