Skip to content

Expose validateIfApplicable and isBindExceptionRequired as protected extension points in ModelAttributeMethodArgumentResolver#36697

Open
Arbaz4Sayyad wants to merge 1 commit intospring-projects:mainfrom
Arbaz4Sayyad:issue-36690-protected-extension-points-clean
Open

Expose validateIfApplicable and isBindExceptionRequired as protected extension points in ModelAttributeMethodArgumentResolver#36697
Arbaz4Sayyad wants to merge 1 commit intospring-projects:mainfrom
Arbaz4Sayyad:issue-36690-protected-extension-points-clean

Conversation

@Arbaz4Sayyad
Copy link
Copy Markdown

Expose validateIfApplicable and isBindExceptionRequired as protected extension points in ModelAttributeMethodArgumentResolver

This change aligns WebFlux with Spring MVC by making validation-related
methods protected extension points, allowing subclasses to customize
validation behavior.

Motivation:
When migrating from Spring MVC to WebFlux, a common customization pattern is to
subclass ModelAttributeMethodProcessor and override validateIfApplicable to apply
group-based or context-aware validation — for example, selecting different @validated
groups based on the HTTP method, tenant context, or feature flags. The same need
exists in WebFlux, but ModelAttributeMethodArgumentResolver does not support it.

Similarly, isBindExceptionRequired is overridden in MVC subclasses to control whether
a binding/validation failure should throw or be silently passed to a BindingResult
parameter — this decision sometimes needs to depend on runtime state, not just
parameter inspection.

Changes:

  • Changed validateIfApplicable from private to protected with Javadoc
  • Introduced isBindExceptionRequired as protected method with Javadoc
  • Replaced private hasErrorsArgument helper with isBindExceptionRequired
  • Updated call site to use isBindExceptionRequired
  • Added test to verify protected methods can be overridden

Precedent:
This follows the same pattern established in PR #24947, which made bindRequestParameters
protected in ModelAttributeMethodArgumentResolver. The class currently exposes two
protected reactive extension points (constructAttribute and bindRequestParameters).
validateIfApplicable sits at the same level in the binding lifecycle and should
follow the same convention.

Testing:

  • All existing tests pass
  • Added new test protectedMethodsCanBeOverridden to verify the protected methods
    can be successfully overridden by subclasses

Behavioral Impact:
No behavioral changes - purely additive changes that enable extension points for
subclasses. Existing behavior is unaffected for any code that does not subclass
ModelAttributeMethodArgumentResolver.

Fixes #36690

…extension points in ModelAttributeMethodArgumentResolver

This change aligns WebFlux with Spring MVC by making validation-related
methods protected extension points, allowing subclasses to customize
validation behavior.

Changes:
- Change validateIfApplicable from private to protected
- Introduce isBindExceptionRequired as protected method
- Replace private hasErrorsArgument helper with isBindExceptionRequired
- Add test to verify protected methods can be overridden

Fixes spring-projects#36690

Signed-off-by: Arbaz4Sayyad <arbaz4sayyad@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ModelAttributeMethodArgumentResolver should expose validateIfApplicable and isBindExceptionRequired as protected extension points

2 participants