Skip to content

@AssertTrue validation failure in private isFoo method causes 500 INTERNAL_SERVER_ERROR [SPR-17055] #21593

@spring-projects-issues

Description

@spring-projects-issues

Adam Chesney opened SPR-17055 and commented

Attached is a zipped up Spring Boot 2.1 SNAPSHOT web project showing the problem.

A method like this:

@JsonIgnore
@AssertTrue
private boolean isNameNotFoo(){
    return name != null && !name.equalsIgnoreCase("foo");
}

In a nested element that appears in a List of items in a request object causes a 500 when it fails validation.

So this json is fine and returns 200:

{"things":[{"name":"bar"}]}

But this json:

{"things":[{"name":"foo"}]}

blows up with 500:

> Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: JSR-303 validated property 'things[0].nameNotFoo' does not have a corresponding accessor for Spring data binding - check your DataBinder's configuration (bean property versus direct field access)] with root cause``org.springframework.beans.NotReadablePropertyException: Invalid property 'things[0].nameNotFoo' of bean class [com.example.validationfail.api.OuterThing]: Bean property 'things[0].nameNotFoo' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
> at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:622) ~[spring-beans-5.1.0.BUILD-SNAPSHOT.jar:5.1.0.BUILD-SNAPSHOT]
> at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:612) ~[spring-beans-5.1.0.BUILD-SNAPSHOT.jar:5.1.0.BUILD-SNAPSHOT]
> at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:104) ~[spring-context-5.1.0.BUILD-SNAPSHOT.jar:5.1.0.BUILD-SNAPSHOT]
> at org.springframework.validation.AbstractBindingResult.getRawFieldValue(AbstractBindingResult.java:284) ~[spring-context-5.1.0.BUILD-SNAPSHOT.jar:5.1.0.BUILD-SNAPSHOT]

Affects: 5.0.8

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions