Skip to content

Commit 3d57425

Browse files
committed
Return rejected value from getFieldValue in case of error
See gh-19877
1 parent d4caaeb commit 3d57425

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,22 @@ public List<FieldError> getFieldErrors() {
125125
@Override
126126
@Nullable
127127
public Object getFieldValue(String field) {
128+
FieldError fieldError = getFieldError(field);
129+
if (fieldError != null) {
130+
return fieldError.getRejectedValue();
131+
}
132+
128133
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(this.target.getClass(), field);
129134
if (pd != null && pd.getReadMethod() != null) {
130135
return ReflectionUtils.invokeMethod(pd.getReadMethod(), this.target);
131136
}
137+
132138
Field rawField = ReflectionUtils.findField(this.target.getClass(), field);
133139
if (rawField != null) {
134140
ReflectionUtils.makeAccessible(rawField);
135141
return ReflectionUtils.getField(rawField, this.target);
136142
}
143+
137144
throw new IllegalArgumentException("Cannot retrieve value for field '" + field +
138145
"' - neither a getter method nor a raw field found");
139146
}

0 commit comments

Comments
 (0)