Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Remove BaseModel since it breaks equals/hashCode contract#112

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Weltraumschaf merged 21 commits intosecureCodeBox:mainfromWeltraumschaf:23_equals
Feb 9, 2024

Conversation

Weltraumschaf
Copy link
Member

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

@WeltraumschafWeltraumschaf self-assigned thisJan 26, 2024
@WeltraumschafWeltraumschaf added the bugSomething isn't working labelJan 26, 2024
@WeltraumschafWeltraumschaf marked this pull request as draftJanuary 26, 2024 19:05
@WeltraumschafWeltraumschaf marked this pull request as ready for reviewJanuary 26, 2024 21:44
@Weltraumschaf
Copy link
MemberAuthor

I suggest reviewing by commits instead of files bc I did a reformatting of all classes in one commit.

J12934
J12934 previously approved these changesJan 30, 2024
Copy link
Member

@J12934J12934 left a 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

@sonarqubecloudSonarQubeCloud
Copy link

Quality Gate PassedQuality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

6 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

…tractProblem of equals and inheritance:As described in this[1] blog post the Object#equals() requires that itfulfills the Liskov Substitution Principle (LSP). Our implemenationbreaks this contract. Even worse, it didn't work at all as descibedin 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 classesfinal and all properties private. This is an implicit requirement of thecontract of hashCode() to avoid memory leaks in collections. (See linkedblog post on Artima for more details.)Actually objects must be immutable -- all fields final -- to guaruanteea stable equal/hashCode behaviour for the whole lifetime of the objects.But this must be further investigated, if this is possible. For now weignore this warning in the test code.1:https://www.artima.com/articles/how-to-write-an-equality-method-in-java2:secureCodeBox#23Signed-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 valueand 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>
…memtationsSigned-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
Since the implementation of isNameEqual returns false, if thevalue in the map is null, we do this for id the same way to beconsistent.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 typesimplementing Model can be wrapped because the service alreadyrequire 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 APISigned-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
@J12934
Copy link
Member

which commits here are new since the last review?
don't want to go through all of them again and with the force pushes & rebases on this branch the dates are wrong and the github ui doesn't show me where to start again.

…ns HaveSigned-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>
@WeltraumschafWeltraumschaf merged commit74aa334 intosecureCodeBox:mainFeb 9, 2024
@WeltraumschafWeltraumschaf deleted the 23_equals branchFebruary 9, 2024 09:01
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@J12934J12934J12934 approved these changes

Assignees

@WeltraumschafWeltraumschaf

Labels
bugSomething isn't working
Projects
Archived in project
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Weltraumschaf@J12934

[8]ページ先頭

©2009-2025 Movatter.jp