Skip to content

Commit 878d262

Browse files
bagyonijzheaux
authored andcommitted
Reimplement some hashCodes according to the currently recommended pattern.
These hashCode implementations seemed suspicious (field hashCodes XORed together with 31). Included caseSensitive in AntPathRequestMatcher.hashCode() to be consistent with equals().
1 parent f44eb0b commit 878d262

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

acl/src/main/java/org/springframework/security/acls/domain/ObjectIdentityImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,9 @@ public String getType() {
152152
*/
153153
@Override
154154
public int hashCode() {
155-
int code = 31;
156-
code ^= this.type.hashCode();
157-
code ^= this.identifier.hashCode();
158-
159-
return code;
155+
int result = this.type.hashCode();
156+
result = 31 * result + this.identifier.hashCode();
157+
return result;
160158
}
161159

162160
@Override

core/src/main/java/org/springframework/security/authentication/jaas/JaasGrantedAuthority.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public String getAuthority() {
5858

5959
@Override
6060
public int hashCode() {
61-
return 31 ^ principal.hashCode() ^ role.hashCode();
61+
int result = this.principal.hashCode();
62+
result = 31 * result + this.role.hashCode();
63+
return result;
6264
}
6365

6466
@Override

web/src/main/java/org/springframework/security/web/access/intercept/RequestKey.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ String getMethod() {
4545

4646
@Override
4747
public int hashCode() {
48-
int code = 31;
49-
code ^= url.hashCode();
50-
51-
if (method != null) {
52-
code ^= method.hashCode();
53-
}
54-
55-
return code;
48+
int result = this.url.hashCode();
49+
result = 31 * result + (this.method != null ? this.method.hashCode() : 0);
50+
return result;
5651
}
5752

5853
@Override

web/src/main/java/org/springframework/security/web/authentication/switchuser/SwitchUserGrantedAuthority.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public String getAuthority() {
7070

7171
@Override
7272
public int hashCode() {
73-
return 31 ^ source.hashCode() ^ role.hashCode();
73+
int result = this.role.hashCode();
74+
result = 31 * result + this.source.hashCode();
75+
return result;
7476
}
7577

7678
@Override

web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,10 @@ public boolean equals(Object obj) {
220220

221221
@Override
222222
public int hashCode() {
223-
int code = 31 ^ this.pattern.hashCode();
224-
if (this.httpMethod != null) {
225-
code ^= this.httpMethod.hashCode();
226-
}
227-
return code;
223+
int result = this.pattern != null ? this.pattern.hashCode() : 0;
224+
result = 31 * result + (this.httpMethod != null ? this.httpMethod.hashCode() : 0);
225+
result = 31 * result + (this.caseSensitive ? 1231 : 1237);
226+
return result;
228227
}
229228

230229
@Override

0 commit comments

Comments
 (0)