You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When validation of a type in a Collection that can't be indexed, e.g. a Set, fails, Hibernate Validator produces a property path with no index. For example:
public final class Input {
@NotEmpty
@Valid
private final Set<URI> nodes;
...
}
If validation of a URI in nodes fails, the property path in the resulting constraint violation is nodes[]. This causes the logic that processes the constraint violations to blow up with a NumberFormatException:
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.parseInt(Integer.java:499)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:794)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:717)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
at org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:105)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:92)
at org.springframework.validation.DataBinder.validate(DataBinder.java:711)
at org.springframework.web.servlet.mvc.method.annotation.support.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:71)
...
Judging by https://forum.hibernate.org/viewtopic.php?f=9&t=1010626 it would appear that the lack of index in the path is expected behaviour for Hibernate Validator. We can probably work around this by using a custom List implementation that also maintains Set semantics, but it'd be nice if Spring coped with the absence of the index more gracefully than it does at the moment.
Resolved through an alternative code path in SpringValidatorPath if we operate against a BindingResult (which we normally do): We take the JSR-303 provided invalid value then and do not even try to extract the field value ourselves, in contrast to what happens with a standard Errors.rejectValue call in Spring.
Note that the end result will differ in the list of field errors: There will be an entry with a "nodes[]." path in there, not allowing for proper association in web forms or the like. If the latter is necessary, using a different JSR-303 provider is the only option, I'm afraid.
Andy Wilkinson opened SPR-8634 and commented
When validation of a type in a Collection that can't be indexed, e.g. a Set, fails, Hibernate Validator produces a property path with no index. For example:
public final class Input {
}
If validation of a URI in nodes fails, the property path in the resulting constraint violation is nodes[]. This causes the logic that processes the constraint violations to blow up with a NumberFormatException:
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.parseInt(Integer.java:499)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:794)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:717)
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99)
at org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:105)
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:92)
at org.springframework.validation.DataBinder.validate(DataBinder.java:711)
at org.springframework.web.servlet.mvc.method.annotation.support.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:71)
...
Judging by https://forum.hibernate.org/viewtopic.php?f=9&t=1010626 it would appear that the lack of index in the path is expected behaviour for Hibernate Validator. We can probably work around this by using a custom List implementation that also maintains Set semantics, but it'd be nice if Spring coped with the absence of the index more gracefully than it does at the moment.
Affects: 3.0.6, 3.1 M2
Issue Links:
Referenced from: commits 1e2f491
The text was updated successfully, but these errors were encountered: