Skip to content

Commit 5f2ecf2

Browse files
committed
#23 Remove BaseModel since it breaks equals/hashCode contract
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 Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent f24e726 commit 5f2ecf2

36 files changed

+245
-220
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>io.securecodebox</groupId>
66
<artifactId>defectdojo-client</artifactId>
7-
<version>2.0.1-SNAPSHOT</version>
7+
<version>3.0.0-SNAPSHOT</version>
88
<packaging>jar</packaging>
99
<name>DefectDojo Client Java</name>
1010
<description>

src/main/java/io/securecodebox/persistence/defectdojo/model/BaseModel.java

-12
This file was deleted.

src/main/java/io/securecodebox/persistence/defectdojo/model/Endpoint.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,38 @@
1414
@Builder
1515
@NoArgsConstructor
1616
@AllArgsConstructor
17-
@EqualsAndHashCode(callSuper = true)
17+
@EqualsAndHashCode
1818
@JsonInclude(JsonInclude.Include.NON_NULL)
19-
public class Endpoint extends BaseModel {
19+
public final class Endpoint implements Model {
2020
@JsonProperty
21-
Long id;
21+
private Long id;// FIXME: Use native type here.
2222

2323
@JsonProperty
24-
String protocol;
24+
private String protocol;
2525

2626
@JsonProperty
27-
String host;
27+
private String host;
2828

2929
@JsonProperty("fqdm")
30-
String fullyQualifiedDomainName;
30+
private String fullyQualifiedDomainName;
3131

3232
@JsonProperty
33-
Long port;
33+
private Long port;// FIXME: Use native type here.
3434

3535
@JsonProperty
36-
String path;
36+
private String path;
3737

3838
@JsonProperty
39-
String query;
39+
private String query;
4040

4141
@JsonProperty
42-
String fragment;
42+
private String fragment;
4343

4444
@JsonProperty
45-
Long product;
45+
private Long product;// FIXME: Use native type here.
4646

4747
@JsonProperty
48-
Boolean mitigated;
48+
private Boolean mitigated;// FIXME: Use native type here.
4949

5050
@Override
5151
public boolean equalsQueryString(Map<String, Object> queryParams) {

src/main/java/io/securecodebox/persistence/defectdojo/model/Engagement.java

+30-30
Original file line numberDiff line numberDiff line change
@@ -15,86 +15,86 @@
1515
@Builder
1616
@NoArgsConstructor
1717
@AllArgsConstructor
18-
@EqualsAndHashCode(callSuper = true)
18+
@EqualsAndHashCode
1919
@JsonInclude(JsonInclude.Include.NON_NULL)
20-
public class Engagement extends BaseModel {
20+
public final class Engagement implements Model {
2121
@JsonProperty("branch_tag")
22-
public String branch;
22+
private String branch;
2323

2424
@JsonProperty
25-
protected Long id;
25+
private Long id;
2626

2727
@JsonProperty
28-
protected String name;
28+
private String name;
2929

3030
@JsonProperty
31-
protected Long product;
31+
private Long product;// FIXME: Use native type here.
3232

3333
@JsonProperty("target_start")
34-
protected String targetStart;
34+
private String targetStart;
3535

3636
@JsonProperty("target_end")
37-
protected String targetEnd;
37+
private String targetEnd;
3838

3939
@JsonProperty
40-
protected Long lead;
40+
private Long lead;// FIXME: Use native type here.
4141

4242
@JsonProperty("engagement_type")
4343
@Builder.Default
44-
protected String engagementType = "CI/CD";
44+
private String engagementType = "CI/CD";
4545

4646
@JsonProperty
4747
@Builder.Default
48-
protected Status status = Status.IN_PROGRESS;
48+
private Status status = Status.IN_PROGRESS;
4949

5050
@JsonProperty
51-
protected List<String> tags;
51+
private List<String> tags;
5252

5353
@JsonProperty
54-
protected String tracker;
54+
private String tracker;
5555

5656
@JsonProperty("build_id")
57-
protected String buildID;
57+
private String buildID;
5858

5959
@JsonProperty("commit_hash")
60-
protected String commitHash;
60+
private String commitHash;
6161

6262
@JsonProperty("source_code_management_uri")
63-
protected String repo;
63+
private String repo;
6464

6565
@JsonProperty("build_server")
66-
protected Long buildServer;
66+
private Long buildServer; // FIXME: Use native type here.
6767

6868
@JsonProperty("source_code_management_server")
69-
protected Long scmServer;
69+
private Long scmServer; // FIXME: Use natvive type here.
7070

7171
@JsonProperty("orchestration_engine")
72-
protected Long orchestrationEngine;
72+
private Long orchestrationEngine; // FIXME: Use natvive type here.
7373

7474
@JsonProperty
75-
protected String description;
75+
private String description;
7676

7777
@JsonProperty("deduplication_on_engagement")
78-
protected boolean deduplicationOnEngagement;
78+
private boolean deduplicationOnEngagement;
7979

8080
@JsonProperty("threat_model")
81-
@Builder.Default
82-
protected Boolean threatModel = false;
81+
@Builder.Default // FIXME: Use native type here.
82+
private Boolean threatModel = false;
8383

8484
@JsonProperty("api_test")
85-
@Builder.Default
86-
protected Boolean apiTest = false;
85+
@Builder.Default // FIXME: Use native type here.
86+
private Boolean apiTest = false;
8787

8888
@JsonProperty("pen_test")
89-
@Builder.Default
90-
protected Boolean penTest = false;
89+
@Builder.Default // FIXME: Use native type here.
90+
private Boolean penTest = false;
9191

9292
@JsonProperty("check_list")
93-
@Builder.Default
94-
protected Boolean checkList = false;
93+
@Builder.Default // FIXME: Use native type here.
94+
private Boolean checkList = false;
9595

9696
@JsonProperty
97-
protected String version;
97+
private String version;
9898

9999
@Override
100100
public boolean equalsQueryString(Map<String, Object> queryParams) {

src/main/java/io/securecodebox/persistence/defectdojo/model/Finding.java

+24-24
Original file line numberDiff line numberDiff line change
@@ -19,94 +19,94 @@
1919
@Builder
2020
@NoArgsConstructor
2121
@AllArgsConstructor
22-
@EqualsAndHashCode(callSuper = true)
22+
@EqualsAndHashCode
2323
@JsonInclude(JsonInclude.Include.NON_NULL)
24-
public class Finding extends BaseModel {
24+
public final class Finding implements Model {
2525
@JsonProperty
26-
Long id;
26+
private Long id;// FIXME: Use native type here.
2727

2828
@JsonProperty
2929
@NonNull
30-
String title;
30+
private String title;
3131

3232
@JsonProperty
3333
@NonNull
34-
String description;
34+
private String description;
3535

3636
@JsonProperty("found_by")
3737
@NonNull
38-
List<Long> foundBy;
38+
private List<Long> foundBy;
3939

4040
@JsonProperty
4141
@NonNull
42-
Severity severity;
42+
private Severity severity;
4343

4444
@JsonProperty
4545
@NonNull
46-
Long test;
46+
private Long test;// FIXME: Use native type here.
4747

4848
@JsonProperty
49-
String mitigation;
49+
private String mitigation;
5050

5151
@JsonProperty
52-
String impact;
52+
private String impact;
5353

5454
@JsonProperty
5555
@NonNull
5656
@Builder.Default
57-
Boolean active = true;
57+
private Boolean active = true;// FIXME: Use native type here.
5858

5959
@JsonProperty
6060
@NonNull
6161
@Builder.Default
62-
Boolean verified = true;
62+
private Boolean verified = true;// FIXME: Use native type here.
6363

6464
@JsonProperty("risk_accepted")
6565
@NonNull
6666
@Builder.Default
67-
Boolean riskAccepted = false;
67+
private Boolean riskAccepted = false;// FIXME: Use native type here.
6868

6969
@JsonProperty("out_of_scope")
7070
@NonNull
7171
@Builder.Default
72-
Boolean outOfScope = false;
72+
private Boolean outOfScope = false;// FIXME: Use native type here.
7373

7474
@JsonProperty
7575
@NonNull
7676
@Builder.Default
77-
Boolean duplicate = false;
77+
private Boolean duplicate = false;// FIXME: Use native type here.
7878

7979
@JsonProperty("duplicate_finding")
8080
@Builder.Default
81-
Long duplicateFinding = null;
81+
private Long duplicateFinding = null;// FIXME: Use native type here.
8282

8383
@JsonProperty("false_p")
8484
@NonNull
8585
@Builder.Default
86-
Boolean falsePositive = false;
86+
private Boolean falsePositive = false;// FIXME: Use native type here.
8787

8888
@JsonProperty("component_name")
89-
String componentName;
89+
private String componentName;
9090

9191
@JsonProperty("component_version")
92-
String componentVersion;
92+
private String componentVersion;
9393

9494
@JsonProperty("file_path")
95-
String filePath;
95+
private String filePath;
9696

9797
@JsonProperty
9898
@NonNull
9999
@Builder.Default
100-
List<Long> endpoints = new LinkedList<>();
100+
private List<Long> endpoints = new LinkedList<>();
101101

102102
@JsonProperty("created")
103-
OffsetDateTime createdAt;
103+
private OffsetDateTime createdAt;
104104

105105
@JsonProperty("mitigated")
106-
OffsetDateTime mitigatedAt;
106+
private OffsetDateTime mitigatedAt;
107107

108108
@JsonProperty("accepted_risks")
109-
List<RiskAcceptance> acceptedRisks;
109+
private List<RiskAcceptance> acceptedRisks;
110110

111111
@JsonProperty("numerical_severity")
112112
public String getNumericalSeverity() {

src/main/java/io/securecodebox/persistence/defectdojo/model/Group.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,24 @@
1515
@Builder
1616
@NoArgsConstructor
1717
@AllArgsConstructor
18-
@EqualsAndHashCode(callSuper = true)
18+
@EqualsAndHashCode
1919
@JsonInclude(JsonInclude.Include.NON_NULL)
20-
public class Group extends BaseModel {
20+
public final class Group implements Model {
2121
@JsonProperty
22-
Long id;
22+
private Long id;// FIXME: Use native type here.
2323

2424
@JsonProperty
2525
@NonNull
26-
String name;
26+
private String name;
2727

2828
@JsonProperty
29-
String description;
29+
private String description;
3030

3131
@JsonProperty
32-
List<Long> users;
32+
private List<Long> users;
3333

3434
@JsonProperty("social_provider")
35-
String socialProvider;
35+
private String socialProvider;
3636

3737
@Override
3838
public boolean equalsQueryString(Map<String, Object> queryParams) {

src/main/java/io/securecodebox/persistence/defectdojo/model/GroupMember.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@
1414
@Builder
1515
@NoArgsConstructor
1616
@AllArgsConstructor
17-
@EqualsAndHashCode(callSuper = true)
17+
@EqualsAndHashCode
1818
@JsonInclude(JsonInclude.Include.NON_NULL)
19-
public class GroupMember extends BaseModel {
19+
public final class GroupMember implements Model {
2020
@JsonProperty
21-
Long id;
21+
private Long id;// FIXME: Use native type here.
2222

2323
@JsonProperty("group_id")
24-
Long group;
24+
private Long group;// FIXME: Use native type here.
2525

2626
@JsonProperty("user_id")
27-
Long user;
27+
private Long user;// FIXME: Use native type here.
2828

2929
@JsonProperty
30-
Long role;
30+
private Long role;// FIXME: Use native type here.
3131

3232
@Override
3333
public boolean equalsQueryString(Map<String, Object> queryParams) {

0 commit comments

Comments
 (0)