Skip to content

Comments

fix: prevent IllegalArgumentException when apiVersion is missing#36249

Closed
fwemaere wants to merge 1 commit intospring-projects:mainfrom
fwemaere:patch-1
Closed

fix: prevent IllegalArgumentException when apiVersion is missing#36249
fwemaere wants to merge 1 commit intospring-projects:mainfrom
fwemaere:patch-1

Conversation

@fwemaere
Copy link

@fwemaere fwemaere commented Feb 3, 2026

Context

When no API versioning is configured, calling
RequestMappingInfo#getMatchingCondition(ServerWebExchange exchange) results throws an exception.

Problem

The exception is thrown from VersionRequestCondition#getMatchingCondition.

When API versioning is disabled, the following line assumes that a version attribute is always present in the exchange:

ApiVersionHolder versionHolder =
        exchange.getRequiredAttribute(HandlerMapping.API_VERSION_ATTRIBUTE);

If no version has been resolved, this attribute is missing, which throws:

java.lang.IllegalArgumentException:
Required attribute 'org.springframework.web.reactive.HandlerMapping.apiVersion' is missing

VersionRequestCondition does not handle the case where API versioning is not configured.
It unconditionally expects HandlerMapping.API_VERSION_ATTRIBUTE to be present, even when no version is defined.

Fix

Checking version == null before makes VersionRequestCondition#getMatchingCondition resilient to the absence of API versioning by safely handling a null or missing API version attribute instead of throwing an exception.

Signed-off-by: François WEMAERE <32339136+fwemaere@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 3, 2026
@rstoyanchev
Copy link
Contributor

The request attribute is set at the level AbstractHandlerMapping, and is required to be present, and it has nothing to do with whether a mapping has a version or not.

Note also a recent change #36276 that has already updated this for efficiency.

@rstoyanchev rstoyanchev added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: invalid An issue that we don't feel is valid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants