Skip to content

NumberFormatException caused by property paths from JSR-303 based validation with no index into a collection [SPR-8634] #13276

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 1e2f491

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions