You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I have a POJO with a Set<> of anything, the tests will not pass if I am using Apache's EqualsBuilder because the hashcode will be the same with a null Set<> and an empty Set<>:
Class com.pojotester.bug.setBug.User has bad 'hashCode' method implementation.
The hashCode method should return different hash codes for non equal objects.
Current implementation returns same hash codes.
Object:
User(firstName=null, authorities=null)
and
User(firstName=null, authorities=[])
should have different hash codes:
23273
and
23273
I see that this was fixed in #153, but it is still happening to me. From what I see, that ticket changed empty sets to be sets with a single Object in SetValueChanger. Unfortunately, the method increaseValue is never being called according to my debugger, and therefore is not solving the problem. Here is a basic app that exposes the bug: https://github.com/wyattjsmith1/PojoTesterSetBug. Just run: ./gradlew test and look at the generated html failure. (I've never shared a git repo, so let me know if you can't access it)
Thanks for your help! I really like this project.
The text was updated successfully, but these errors were encountered:
Slightly related, but I prefer to always return an empty collection if there is a null one saved. This causes an error with the getter method:
Class one.rizzo.backend.auth.domain.User has bad 'getter' method implementation.
The getter method for field 'private java.util.Set one.rizzo.backend.auth.domain.User.authorities' should return field value.
Current implementation returns different value.
Expected value:
[]
but was:
null
Not sure if this should be a separate ticket. Also, the expected value should be null, and the actual value is [].
I tried this library today and had this problem with sets as well. In general, however, why are hash codes required to be different for different objects. That's not how hash codes are designed to work. An object containing a null set and empty set may generate the same hash code, but the equals method would not return true.
https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--
"It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables."
If I have a POJO with a Set<> of anything, the tests will not pass if I am using Apache's EqualsBuilder because the hashcode will be the same with a null Set<> and an empty Set<>:
I see that this was fixed in #153, but it is still happening to me. From what I see, that ticket changed empty sets to be sets with a single Object in
SetValueChanger
. Unfortunately, the method increaseValue is never being called according to my debugger, and therefore is not solving the problem. Here is a basic app that exposes the bug: https://github.com/wyattjsmith1/PojoTesterSetBug. Just run:./gradlew test
and look at the generated html failure. (I've never shared a git repo, so let me know if you can't access it)Thanks for your help! I really like this project.
The text was updated successfully, but these errors were encountered: