Description
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 {
@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.
Affects: 3.0.6, 3.1 M2
Issue Links:
- Hibernate Class Level Validators cause IllegalArgument Exception [SPR-8895] #13536 Hibernate Class Level Validators cause IllegalArgument Exception
- NumberFormatException caused by property paths from JSR-303 based validation with no index into a collection [SPR-16177] #20725 NumberFormatException caused by property paths from JSR-303 based validation with no index into a collection
Referenced from: commits 1e2f491