Explorar o código

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().
Bagyoni Attila %!s(int64=6) %!d(string=hai) anos
pai
achega
878d262a26

+ 3 - 5
acl/src/main/java/org/springframework/security/acls/domain/ObjectIdentityImpl.java

@@ -152,11 +152,9 @@ public class ObjectIdentityImpl implements ObjectIdentity {
 	 */
 	@Override
 	public int hashCode() {
-		int code = 31;
-		code ^= this.type.hashCode();
-		code ^= this.identifier.hashCode();
-
-		return code;
+		int result = this.type.hashCode();
+		result = 31 * result + this.identifier.hashCode();
+		return result;
 	}
 
 	@Override

+ 3 - 1
core/src/main/java/org/springframework/security/authentication/jaas/JaasGrantedAuthority.java

@@ -58,7 +58,9 @@ public final class JaasGrantedAuthority implements GrantedAuthority {
 
 	@Override
 	public int hashCode() {
-		return 31 ^ principal.hashCode() ^ role.hashCode();
+		int result = this.principal.hashCode();
+		result = 31 * result + this.role.hashCode();
+		return result;
 	}
 
 	@Override

+ 3 - 8
web/src/main/java/org/springframework/security/web/access/intercept/RequestKey.java

@@ -45,14 +45,9 @@ public class RequestKey {
 
 	@Override
 	public int hashCode() {
-		int code = 31;
-		code ^= url.hashCode();
-
-		if (method != null) {
-			code ^= method.hashCode();
-		}
-
-		return code;
+		int result = this.url.hashCode();
+		result = 31 * result + (this.method != null ? this.method.hashCode() : 0);
+		return result;
 	}
 
 	@Override

+ 3 - 1
web/src/main/java/org/springframework/security/web/authentication/switchuser/SwitchUserGrantedAuthority.java

@@ -70,7 +70,9 @@ public final class SwitchUserGrantedAuthority implements GrantedAuthority {
 
 	@Override
 	public int hashCode() {
-		return 31 ^ source.hashCode() ^ role.hashCode();
+		int result = this.role.hashCode();
+		result = 31 * result + this.source.hashCode();
+		return result;
 	}
 
 	@Override

+ 4 - 5
web/src/main/java/org/springframework/security/web/util/matcher/AntPathRequestMatcher.java

@@ -220,11 +220,10 @@ public final class AntPathRequestMatcher
 
 	@Override
 	public int hashCode() {
-		int code = 31 ^ this.pattern.hashCode();
-		if (this.httpMethod != null) {
-			code ^= this.httpMethod.hashCode();
-		}
-		return code;
+		int result = this.pattern != null ? this.pattern.hashCode() : 0;
+		result = 31 * result + (this.httpMethod != null ? this.httpMethod.hashCode() : 0);
+		result = 31 * result + (this.caseSensitive ? 1231 : 1237);
+		return result;
 	}
 
 	@Override