When versionRequired is false and defaultVersion is not set, an IllegalStateException occurs if the selected endpoint has a version attribute.

Caused by: java.lang.IllegalStateException: No API version attribute
    at org.springframework.util.Assert.state(Assert.java:80)
    at org.springframework.web.servlet.mvc.condition.VersionRequestCondition.handleMatch(VersionRequestCondition.java:151)
    at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleMatch(RequestMappingInfoHandlerMapping.java:134)
    at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleMatch(RequestMappingInfoHandlerMapping.java:68)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:430)
    at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:376)
    at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:116)
    at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:68)

Comment From: DhruvTheDev1

Spring's version request handler throws java.lang.IllegalStateException: No API version attribute as it expects either a default version or the API version to be explicitly required on requests.

@rstoyanchev Can I open a PR for this?

public void handleMatch(HttpServletRequest request) {
        if (this.version != null && !this.baselineVersion) {
            Comparable<?> version = (Comparable<?>) request.getAttribute(HandlerMapping.API_VERSION_ATTRIBUTE);
            Assert.state(version != null, "No API version attribute");
            if (!this.version.equals(version)) {
                throw new NotAcceptableApiVersionException(version.toString());
            }
        }
    }

Modify the method with a check for missing version attribute? If version attribute is missing and versionRequired is false, skip exception but will need to add versionRequired field private final boolean versionRequired I believe.

Or just add if version is missing (version == null) then return so it avoids the exception when the version is missing.

Comment From: rstoyanchev

@DhruvTheDev1 thanks for the offer, but I need to have a closer look before I can answer. It's also closely related to #35237 and the two need to be considered tother.