Skip to content

Message interpolation by MVC and WebFlux's Validators does not work correctly in a native image #48828

@Gadnex

Description

@Gadnex

Spring Boot version: 4.0.1

Current Behavior with GraalVM Native Image

When doing Controller Bean Validation and injecting the BindingResult into the MVC template,
the field error default messages have not been interpolated. This used to work with Spring Boot 3.x native images.

Image

Current Behavior with JVM

When running the application locally or with a non-native image the BindingResult error messages are interpolated correctly.

Image

Expected Behavior

BindingResult error message interpolation should work correctly as it does with JVM.

Context

Here is a sample of the code I used to inject the BindingResult into the MVC template.
When logging the fieldError.getDefaultMessage() in the controller I can already see the error before the MCV template engine gets involved.

@PostMapping
public String addPerson(
        @ModelAttribute @Valid Person person, BindingResult bindingResult, Model model) {
    if (bindingResult.hasErrors()) {
        for (FieldError fieldError : bindingResult.getFieldErrors()) {
            log.error("error: {}", fieldError.getDefaultMessage());
        }
        model.addAttribute("result", bindingResult);
        return "AddPerson";
    }
    PersonController.PERSON = person;
    return "redirect:/person";
}

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions