Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotReadablePropertyException on validated list in request body when there are validation errors #31835

Closed
plc010 opened this issue Dec 13, 2023 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another

Comments

@plc010
Copy link

plc010 commented Dec 13, 2023

Affects: 6.1.1 (Spring Boot 3.2.0)

Not sure if this is an issue or expected behavior and I missed something in the upgrade guide. Spring Boot 3.1.6 and earlier produce expected binding result errors.

The sample code attached will produce the exception below when a constraint violation (blank dog name) is in the request

org.springframework.beans.NotReadablePropertyException: Invalid property 'list[0]' of bean class [com.demo.validationdemo.Dog]: Bean property 'list[0]' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

Sample request body with constraint violation:

[
  {
    "name": ""
  }
]

With Spring Boot 3.1.6 and earlier, the expected binding results below are produced:

Field error in object 'dogs' on field 'list[0].name': rejected value []; codes [NotEmpty.dogs.list[0].name,NotEmpty.dogs.list.name,NotEmpty.list[0].name,NotEmpty.list.name,NotEmpty.name,NotEmpty.java.lang.String,NotEmpty]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [dogs.list[0].name,list[0].name]; arguments []; default message [list[0].name]]; default message [must not be empty]

I have tried changing the data binder to allow direct field access, but that did not resolve the issue. Stepping through the code it seems the list property of the Dogs class is not an available property to the AbstractNestablePropertyAccessor class as it is in Spring Boot 3.1.6 and earlier.

Update:
I've found that if I replace the @Valid annotation on the request body in the controller method with @Validated the binding errors match the behavior seen in Spring Boot 3.1.6.

Change

ResponseEntity<Void> uploadList(@RequestBody @Valid @NotNull Dogs dogs, BindingResult bindingResult) {

to

ResponseEntity<Void> uploadList(@RequestBody @Validated @NotNull Dogs dogs, BindingResult bindingResult) {

validation-demo.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 13, 2023
@rstoyanchev rstoyanchev self-assigned this Dec 18, 2023
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Dec 18, 2023
@rstoyanchev rstoyanchev added this to the 6.1.3 milestone Dec 19, 2023
@rstoyanchev rstoyanchev added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 19, 2023
@sbrannen sbrannen changed the title NotReadablePropertyException on validated list in request body when there are validation errors NotReadablePropertyException on validated list in request body when there are validation errors Dec 19, 2023
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Dec 19, 2023

Thanks for the sample. The issue is a subset of #31746 where the problem is described more broadly. It is related to changes for #31530. For now, I am closing this as superseded, but will confirm any fixes with the sample.

@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2023
@rstoyanchev rstoyanchev removed this from the 6.1.3 milestone Dec 19, 2023
@rstoyanchev rstoyanchev added status: superseded An issue that has been superseded by another and removed type: regression A bug that is also a regression labels Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

3 participants