-
Notifications
You must be signed in to change notification settings - Fork 12
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
Remove BaseModel since it breaks equals/hashCode contract #112
Conversation
973d6a9
to
36b1e8b
Compare
I suggest reviewing by commits instead of files bc I did a reformatting of all classes in one commit. |
src/main/java/io/securecodebox/persistence/defectdojo/model/Response.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks generally good added a couple of comments here to todo question in case that helps give some context
src/main/java/io/securecodebox/persistence/defectdojo/model/UserProfile.java
Outdated
Show resolved
Hide resolved
36b1e8b
to
822f4bb
Compare
8b712c4
to
4949e94
Compare
2bf7eaf
to
b8c79e9
Compare
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 6 New issues |
…tract Problem of equals and inheritance: As described in this[1] blog post the Object#equals() requires that it fulfills the Liskov Substitution Principle (LSP). Our implemenation breaks this contract. Even worse, it didn't work at all as descibed in issue 23[2]. Since the BaseModel class does not have any properties, we can remove it. This patch removes this obsolete class. Also it makes all model classes final and all properties private. This is an implicit requirement of the contract of hashCode() to avoid memory leaks in collections. (See linked blog post on Artima for more details.) Actually objects must be immutable -- all fields final -- to guaruantee a stable equal/hashCode behaviour for the whole lifetime of the objects. But this must be further investigated, if this is possible. For now we ignore this warning in the test code. 1: https://www.artima.com/articles/how-to-write-an-equality-method-in-java 2: secureCodeBox#23 Signed-off-by: Sven Strittmatter <[email protected]>
Native types should be favored over boxed types for two reasons: 1. Boxed types introduce more verbose code. 2. Boxed types introduce possible NPE. Since native types reduces code clutter because they have a default value and they also can not be null, we switched to native type fields. Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Also add missing null check in implementation. Signed-off-by: Sven Strittmatter <[email protected]>
…memtations Signed-off-by: Sven Strittmatter <[email protected]>
Since the implementation of isNameEqual returns false, if the value in the map is null, we do this for id the same way to be consistent. Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
This is necessary to avoid that something else than types implementing Model can be wrapped because the service already require this by upper bounds. Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
- Simplify by removing unnecessary setup method. - Use distinct values in fixture to make it easier spotting bugs. Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
…ic API Signed-off-by: Sven Strittmatter <[email protected]>
b8c79e9
to
490e584
Compare
which commits here are new since the last review? |
src/main/java/io/securecodebox/persistence/defectdojo/model/PaginatedResult.java
Outdated
Show resolved
Hide resolved
src/main/java/io/securecodebox/persistence/defectdojo/model/PaginatedResult.java
Outdated
Show resolved
Hide resolved
src/main/java/io/securecodebox/persistence/defectdojo/model/PaginatedResult.java
Outdated
Show resolved
Hide resolved
src/main/java/io/securecodebox/persistence/defectdojo/model/ScanFile.java
Outdated
Show resolved
Hide resolved
…ns Have Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Signed-off-by: Sven Strittmatter <[email protected]>
Problem of equals and inheritance:
As described in this[1] blog post the Object#equals() requires that it fulfills the Liskov Substitution Principle (LSP). Our implemenation breaks this contract. Even worse, it didn't work at all as descibed in issue 23[2].
Since the BaseModel class does not have any properties, we can remove it.
This patch removes this obsolete class. Also it makes all model classes final and all properties private. This is an implicit requirement of the contract of hashCode() to avoid memory leaks in collections. (See linked blog post on Artima for more details.)
Actually objects must be immutable -- all fields final -- to guaruantee a stable equal/hashCode behaviour for the whole lifetime of the objects. But this must be further investigated, if this is possible. For now we ignore this warning in the test code.
1: https://www.artima.com/articles/how-to-write-an-equality-method-in-java
2: #23