Skip to content

Conversation

@Gautam-aman
Copy link

Summary

This PR improves Spring MVC request parameter binding for primitive boolean
types in two edge cases:

  1. Invalid boolean values for @RequestParam boolean now consistently
    result in MethodArgumentTypeMismatchException, leading to HTTP 400.
  2. Missing primitive boolean parameters declared with
    @RequestParam(required = false) now default to false instead of
    raising a type mismatch exception.

Motivation

Previously:

  • Invalid boolean values could fail inconsistently.
  • Primitive boolean parameters with required=false would still raise
    TypeMismatchException when missing, despite being optional.

This behavior was surprising and inconsistent with developer expectations.

Changes

  • Updated AbstractNamedValueMethodArgumentResolver to correctly handle
    missing primitive boolean parameters when required=false.
  • Ensured invalid boolean values fail fast with a consistent exception.
  • Added regression tests in RequestMappingHandlerAdapterTests.

Impact

  • Backward-compatible
  • Improves correctness and developer experience
  • No public API changes

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 22, 2025
Signed-off-by: Aman Gautam <amangautam2128@gmail.com>
Signed-off-by: Aman Gautam <amangautam2128@gmail.com>
@Gautam-aman Gautam-aman force-pushed the fix/primitive-requestparam-required-false branch from cc8c56d to a5518df Compare December 22, 2025 20:32
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.

2 participants