Consistent equals implementations across class hierarchies

Issue: SPR-13951
This commit is contained in:
Juergen Hoeller
2016-02-17 16:57:29 +01:00
parent ac3847bf4a
commit ac44f9edd9
5 changed files with 14 additions and 20 deletions

View File

@@ -106,7 +106,7 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable,
* the last one in the codes array.
*/
public String getCode() {
return (this.codes != null && this.codes.length > 0) ? this.codes[this.codes.length - 1] : null;
return (this.codes != null && this.codes.length > 0 ? this.codes[this.codes.length - 1] : null);
}
@Override
@@ -153,9 +153,9 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable,
return false;
}
MessageSourceResolvable otherResolvable = (MessageSourceResolvable) other;
return ObjectUtils.nullSafeEquals(getCodes(), otherResolvable.getCodes()) &&
return (ObjectUtils.nullSafeEquals(getCodes(), otherResolvable.getCodes()) &&
ObjectUtils.nullSafeEquals(getArguments(), otherResolvable.getArguments()) &&
ObjectUtils.nullSafeEquals(getDefaultMessage(), otherResolvable.getDefaultMessage());
ObjectUtils.nullSafeEquals(getDefaultMessage(), otherResolvable.getDefaultMessage()));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -112,9 +112,9 @@ public class FieldError extends ObjectError {
return false;
}
FieldError otherError = (FieldError) other;
return getField().equals(otherError.getField()) &&
return (getField().equals(otherError.getField()) &&
ObjectUtils.nullSafeEquals(getRejectedValue(), otherError.getRejectedValue()) &&
isBindingFailure() == otherError.isBindingFailure();
isBindingFailure() == otherError.isBindingFailure());
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ public class ObjectError extends DefaultMessageSourceResolvable {
if (this == other) {
return true;
}
if (getClass() != other.getClass() || !super.equals(other)) {
if (other == null || other.getClass() != getClass() || !super.equals(other)) {
return false;
}
ObjectError otherError = (ObjectError) other;