Skip to content

Commit 3fe2d03

Browse files
committed
fixed AbstractBindingResult to avoid NPE in "hashCode()" if target is null (SPR-7682)
1 parent a780a4a commit 3fe2d03

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

org.springframework.context/src/main/java/org/springframework/validation/AbstractBindingResult.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 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.
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.beans.PropertyEditorRegistry;
3030
import org.springframework.util.Assert;
31+
import org.springframework.util.ObjectUtils;
3132
import org.springframework.util.StringUtils;
3233

3334
/**
@@ -337,13 +338,13 @@ public boolean equals(Object other) {
337338
}
338339
BindingResult otherResult = (BindingResult) other;
339340
return (getObjectName().equals(otherResult.getObjectName()) &&
340-
getTarget().equals(otherResult.getTarget()) &&
341+
ObjectUtils.nullSafeEquals(getTarget(), otherResult.getTarget()) &&
341342
getAllErrors().equals(otherResult.getAllErrors()));
342343
}
343344

344345
@Override
345346
public int hashCode() {
346-
return getObjectName().hashCode() * 29 + getTarget().hashCode();
347+
return getObjectName().hashCode();
347348
}
348349

349350

0 commit comments

Comments
 (0)