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
{{ message }}
Repository navigation
Request to Change Functionality of Models equals() Method #23
Currently for all model classes which extends DefectDojoModel the equals method will not return true even when two models have the exact same field values. The only time equals will return true it calls it on itself.
For example, using the model User:
//Create two Users using the no args constructors, all fields for the created users will be null.
User user1 = new User();
User user2 = new User();
//This will be false even though all fields match.
System.out.println(user.equals(user2));
//Create two Users using the all args constructor, with the same fields.
User userFullArgs1 = new User(1l, "username", "firstname", "lastname");
User userFullArgs2 = new User(1l, "username", "firstname", "lastname");
//This will be false even though all fields match.
System.out.println(userFullArgs1.equals(userFullArgs2));
//The following two lines will be true.
System.out.println(user1.equals(user1));
System.out.println(userFullArgs2.equals(useFullArgs2));
With the current implementation of the models the equals method will never return true unless it calls it on itself.
The reason behind this behavior is due to the @EqualsAndHashCode(callSuper = true) annotation within the models. The callSuper = true flag introduces logic into the equals method that calls super.equals() the super would be the parent class DefectDojoModel. Since DefectDojoModel does not have an equals() method it inherits the Object.equals() implementation. Object.equals() will only return true if the object references are the same, regardless of any field values. Hence the behavior above.
A proposed change would be to make it so that the equals method would return true in the case that all fields are matching. This can be accomplished by changing the @EqualsAndHashCode(callSuper = true) annotation from true to false, or removing the parenthesis portion, or removing that annotation entirely. All three suggestions should ultimately have the same effect.
Activity
secureCodeBox#23 Add failing tests to reproduce broken equals impleme…
secureCodeBox#23 Add failing tests to reproduce broken equals impleme…
secureCodeBox#23 Add failing tests to reproduce broken equals impleme…
secureCodeBox#23 Add failing tests to reproduce broken equals impleme…
secureCodeBox#23 Add failing tests to reproduce broken equals impleme…
secureCodeBox#23 Add failing tests to reproduce broken equals impleme…
#23 Add failing tests to reproduce broken equals implementtion
secureCodeBox#23 Remove BaseModel since it breaks equals/hashCode con…
secureCodeBox#23 Use native types as model's field types
74 remaining items
#23 Add More Questions to PaginatedResult
#23 Clean Test Code
#23 Document Requirement for Null Values
#23 Remove Unnecessary Code Clutter
#23 Clean Code
#23 Clean Test Code
#23 Add TODO Hint to Remove Checked Exceptions from Public API
#23 Add Identical Behaviour Likethe Others Implementations Have
#23 Fix copy Paste Error in JavaDoc
Weltraumschaf commentedon Feb 9, 2024
Fixed.
Revert "secureCodeBox#23 Use native types as model's field types"
Revert "secureCodeBox#23 Use native types as model's field types"
Revert "secureCodeBox#23 Use native types as model's field types"