Skip to content

Commit 5f9b2db

Browse files
committed
turn NotReadablePropertyException into JSR-303 oriented IllegalStateException
1 parent 4cef52a commit 5f9b2db

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2010 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.
@@ -23,6 +23,7 @@
2323
import javax.validation.metadata.BeanDescriptor;
2424
import javax.validation.metadata.ConstraintDescriptor;
2525

26+
import org.springframework.beans.NotReadablePropertyException;
2627
import org.springframework.context.support.DefaultMessageSourceResolvable;
2728
import org.springframework.util.Assert;
2829
import org.springframework.validation.Errors;
@@ -76,10 +77,17 @@ public void validate(Object target, Errors errors) {
7677
String field = violation.getPropertyPath().toString();
7778
FieldError fieldError = errors.getFieldError(field);
7879
if (fieldError == null || !fieldError.isBindingFailure()) {
79-
errors.rejectValue(field,
80-
violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(),
81-
getArgumentsForConstraint(errors.getObjectName(), field, violation.getConstraintDescriptor()),
82-
violation.getMessage());
80+
try {
81+
errors.rejectValue(field,
82+
violation.getConstraintDescriptor().getAnnotation().annotationType().getSimpleName(),
83+
getArgumentsForConstraint(errors.getObjectName(), field, violation.getConstraintDescriptor()),
84+
violation.getMessage());
85+
}
86+
catch (NotReadablePropertyException ex) {
87+
throw new IllegalStateException("JSR-303 validated property '" + field +
88+
"' does not have a corresponding accessor for Spring data binding - " +
89+
"check your DataBinder's configuration (bean property versus direct field access)", ex);
90+
}
8391
}
8492
}
8593
}

0 commit comments

Comments
 (0)