spring-projects / spring-projects/spring-framework

`MethodValidationAdapter` ignores cross-parameter violations when `adapt-constraint-violations` is enabled

Open
#36,666 2 comments 0 reactions 1 assignee View on GitHub

@rstoyanchev is already working on this.

Since May 21, 2026.

in: web type: bug
Dominant language
Java
Stars
60.2k
Forks
38.8k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

Description:
In a Spring MVC REST Controller, when a cross-parameter validation constraint (annotated with @SupportedValidationTarget(ValidationTarget.PARAMETERS)) is applied to a method, the validation fails to interrupt the request flow if spring.validation.method.adapt-constraint-violations is set to true.

The validator is correctly invoked and returns false, but no exception is triggered, and the controller method is executed anyway.

Analysis:
The issue resides in how MethodValidator handles the MethodValidationResult.

When a cross-parameter constraint fails, result.getParameterValidationResults() is empty, while result.getCrossParameterValidationResults() contains the violations.
However, the current logic only seems to trigger an exception based on individual parameter results.

Specifically, in the current Spring Framework 6.2.15 source MethodValidator#applyArgumentValidation, the MethodValidationException is triggered only when result.getParameterValidationResults() is not empty (checked through result.hasError()), the method applyArgumentValidation never check result.getCrossParameterValidationResults().

Steps to reproduce:

  1. Create a REST Controller with a method-level cross-parameter constraint.
  2. Set spring.validation.method.adapt-constraint-violations=true in application.yml.
  3. Invoke the endpoint with arguments that trigger a validation failure.
  4. Observed: The controller method is executed (returns HTTP 200).
  5. Expected: A MethodValidationException should be thrown before the controller method is invoked.

Please see https://github.com/zerikv/spring-issue-36666, this repo contains a minimal spring-boot project which reproduce the problem.

Environment:

  • Spring Boot: 3.5.10
  • Spring Framework: 6.2.15
  • JDK: 21

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.