Skip to content

Commit 0c48864

Browse files
committed
HV-665 Adding all attributes to ConstraintViolationImpl#equals() and hashCode()
1 parent 4e38b47 commit 0c48864

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

engine/src/main/java/org/hibernate/validator/internal/engine/ConstraintViolationImpl.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.hibernate.validator.internal.engine;
1818

19+
import java.io.Serializable;
1920
import java.lang.annotation.ElementType;
2021
import javax.validation.ConstraintViolation;
2122
import javax.validation.Path;
@@ -25,7 +26,7 @@
2526
* @author Emmanuel Bernard
2627
* @author Hardy Ferentschik
2728
*/
28-
public class ConstraintViolationImpl<T> implements ConstraintViolation<T>, java.io.Serializable {
29+
public class ConstraintViolationImpl<T> implements ConstraintViolation<T>, Serializable {
2930

3031
private static final long serialVersionUID = -4970067626703103139L;
3132

@@ -53,34 +54,42 @@ public ConstraintViolationImpl(String messageTemplate, String interpolatedMessag
5354
this.elementType = elementType;
5455
}
5556

57+
@Override
5658
public final String getMessage() {
5759
return interpolatedMessage;
5860
}
5961

62+
@Override
6063
public final String getMessageTemplate() {
6164
return messageTemplate;
6265
}
6366

67+
@Override
6468
public final T getRootBean() {
6569
return rootBean;
6670
}
6771

72+
@Override
6873
public final Class<T> getRootBeanClass() {
6974
return rootBeanClass;
7075
}
7176

77+
@Override
7278
public final Object getLeafBean() {
7379
return leafBeanInstance;
7480
}
7581

82+
@Override
7683
public final Object getInvalidValue() {
7784
return value;
7885
}
7986

87+
@Override
8088
public final Path getPropertyPath() {
8189
return propertyPath;
8290
}
8391

92+
@Override
8493
public final ConstraintDescriptor<?> getConstraintDescriptor() {
8594
return this.constraintDescriptor;
8695
}
@@ -91,11 +100,11 @@ public boolean equals(Object o) {
91100
if ( this == o ) {
92101
return true;
93102
}
94-
if ( !( o instanceof ConstraintViolationImpl ) ) {
103+
if ( o == null || getClass() != o.getClass() ) {
95104
return false;
96105
}
97106

98-
ConstraintViolationImpl<?> that = ( ConstraintViolationImpl<?> ) o;
107+
ConstraintViolationImpl<?> that = (ConstraintViolationImpl<?>) o;
99108

100109
if ( interpolatedMessage != null ? !interpolatedMessage.equals( that.interpolatedMessage ) : that.interpolatedMessage != null ) {
101110
return false;
@@ -109,9 +118,18 @@ public boolean equals(Object o) {
109118
if ( leafBeanInstance != null ? !leafBeanInstance.equals( that.leafBeanInstance ) : that.leafBeanInstance != null ) {
110119
return false;
111120
}
121+
if ( constraintDescriptor != null ? !constraintDescriptor.equals( that.constraintDescriptor ) : that.constraintDescriptor != null ) {
122+
return false;
123+
}
112124
if ( elementType != null ? !elementType.equals( that.elementType ) : that.elementType != null ) {
113125
return false;
114126
}
127+
if ( messageTemplate != null ? !messageTemplate.equals( that.messageTemplate ) : that.messageTemplate != null ) {
128+
return false;
129+
}
130+
if ( rootBeanClass != null ? !rootBeanClass.equals( that.rootBeanClass ) : that.rootBeanClass != null ) {
131+
return false;
132+
}
115133
if ( value != null ? !value.equals( that.value ) : that.value != null ) {
116134
return false;
117135
}
@@ -126,6 +144,9 @@ public int hashCode() {
126144
result = 31 * result + ( rootBean != null ? rootBean.hashCode() : 0 );
127145
result = 31 * result + ( leafBeanInstance != null ? leafBeanInstance.hashCode() : 0 );
128146
result = 31 * result + ( value != null ? value.hashCode() : 0 );
147+
result = 31 * result + ( constraintDescriptor != null ? constraintDescriptor.hashCode() : 0 );
148+
result = 31 * result + ( messageTemplate != null ? messageTemplate.hashCode() : 0 );
149+
result = 31 * result + ( rootBeanClass != null ? rootBeanClass.hashCode() : 0 );
129150
result = 31 * result + ( elementType != null ? elementType.hashCode() : 0 );
130151
return result;
131152
}

0 commit comments

Comments
 (0)