Skip to content

Commit ac44f9e

Browse files
committed
Consistent equals implementations across class hierarchies
Issue: SPR-13951
1 parent ac3847b commit ac44f9e

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

spring-context/src/main/java/org/springframework/context/support/DefaultMessageSourceResolvable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public String[] getCodes() {
106106
* the last one in the codes array.
107107
*/
108108
public String getCode() {
109-
return (this.codes != null && this.codes.length > 0) ? this.codes[this.codes.length - 1] : null;
109+
return (this.codes != null && this.codes.length > 0 ? this.codes[this.codes.length - 1] : null);
110110
}
111111

112112
@Override
@@ -153,9 +153,9 @@ public boolean equals(Object other) {
153153
return false;
154154
}
155155
MessageSourceResolvable otherResolvable = (MessageSourceResolvable) other;
156-
return ObjectUtils.nullSafeEquals(getCodes(), otherResolvable.getCodes()) &&
156+
return (ObjectUtils.nullSafeEquals(getCodes(), otherResolvable.getCodes()) &&
157157
ObjectUtils.nullSafeEquals(getArguments(), otherResolvable.getArguments()) &&
158-
ObjectUtils.nullSafeEquals(getDefaultMessage(), otherResolvable.getDefaultMessage());
158+
ObjectUtils.nullSafeEquals(getDefaultMessage(), otherResolvable.getDefaultMessage()));
159159
}
160160

161161
@Override

spring-context/src/main/java/org/springframework/validation/FieldError.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -112,9 +112,9 @@ public boolean equals(Object other) {
112112
return false;
113113
}
114114
FieldError otherError = (FieldError) other;
115-
return getField().equals(otherError.getField()) &&
115+
return (getField().equals(otherError.getField()) &&
116116
ObjectUtils.nullSafeEquals(getRejectedValue(), otherError.getRejectedValue()) &&
117-
isBindingFailure() == otherError.isBindingFailure();
117+
isBindingFailure() == otherError.isBindingFailure());
118118
}
119119

120120
@Override

spring-context/src/main/java/org/springframework/validation/ObjectError.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ public boolean equals(Object other) {
7878
if (this == other) {
7979
return true;
8080
}
81-
if (getClass() != other.getClass() || !super.equals(other)) {
81+
if (other == null || other.getClass() != getClass() || !super.equals(other)) {
8282
return false;
8383
}
8484
ObjectError otherError = (ObjectError) other;

spring-test/src/main/java/org/springframework/test/context/MergedContextConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -401,7 +401,7 @@ public boolean equals(Object other) {
401401
if (this == other) {
402402
return true;
403403
}
404-
if (!(other instanceof MergedContextConfiguration)) {
404+
if (other == null || other.getClass() != getClass()) {
405405
return false;
406406
}
407407

spring-test/src/main/java/org/springframework/test/context/web/WebMergedContextConfiguration.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -161,14 +161,8 @@ public String getResourceBasePath() {
161161
*/
162162
@Override
163163
public boolean equals(Object other) {
164-
if (this == other) {
165-
return true;
166-
}
167-
if (!(other instanceof WebMergedContextConfiguration)) {
168-
return false;
169-
}
170-
WebMergedContextConfiguration otherConfig = (WebMergedContextConfiguration) other;
171-
return super.equals(otherConfig) && this.getResourceBasePath().equals(otherConfig.getResourceBasePath());
164+
return (this == other || (super.equals(other) &&
165+
this.resourceBasePath.equals(((WebMergedContextConfiguration) other).resourceBasePath)));
172166
}
173167

174168
/**
@@ -178,7 +172,7 @@ public boolean equals(Object other) {
178172
*/
179173
@Override
180174
public int hashCode() {
181-
return 31 * super.hashCode() + this.resourceBasePath.hashCode();
175+
return super.hashCode() * 31 + this.resourceBasePath.hashCode();
182176
}
183177

184178
/**

0 commit comments

Comments
 (0)