Remove BaseModel since it breaks equals/hashCode contract#112
Merged
Weltraumschaf merged 21 commits intosecureCodeBox:mainfrom Feb 9, 2024
Merged
Remove BaseModel since it breaks equals/hashCode contract#112Weltraumschaf merged 21 commits intosecureCodeBox:mainfrom
Weltraumschaf merged 21 commits intosecureCodeBox:mainfrom
Conversation
973d6a9 to
36b1e8b
Compare
Member
Author
|
I suggest reviewing by commits instead of files bc I did a reformatting of all classes in one commit. |
J12934
reviewed
Jan 30, 2024
src/main/java/io/securecodebox/persistence/defectdojo/model/Response.java
Outdated
Show resolved
Hide resolved
J12934
previously approved these changes
Jan 30, 2024
Member
J12934
left a comment
There was a problem hiding this comment.
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
|
…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 <sven.strittmatter@iteratec.com>
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 <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Also add missing null check in implementation. Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
…memtations Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
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 <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
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 <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
- Simplify by removing unnecessary setup method. - Use distinct values in fixture to make it easier spotting bugs. Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
…ic API Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
b8c79e9 to
490e584
Compare
Member
|
which commits here are new since the last review? |
J12934
reviewed
Feb 6, 2024
src/main/java/io/securecodebox/persistence/defectdojo/model/PaginatedResult.java
Outdated
Show resolved
Hide resolved
J12934
reviewed
Feb 6, 2024
src/main/java/io/securecodebox/persistence/defectdojo/model/PaginatedResult.java
Outdated
Show resolved
Hide resolved
J12934
reviewed
Feb 6, 2024
src/main/java/io/securecodebox/persistence/defectdojo/model/PaginatedResult.java
Outdated
Show resolved
Hide resolved
J12934
reviewed
Feb 6, 2024
src/main/java/io/securecodebox/persistence/defectdojo/model/ScanFile.java
Outdated
Show resolved
Hide resolved
…ns Have Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
J12934
approved these changes
Feb 7, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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