Repository navigation
fix: Read method request mappings from the single annotation Spring registers (#672) - #707
Merged
Merged
Conversation
…p the unused duplicate-mapping visitor (#672)
|
This was referenced Oct 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #672
Method-level request mappings were read from declared annotation values, and from every mapping annotation at once.
Spring does neither.
What Spring does
RequestMappingHandlerMapping.createRequestMappingInfo(spring-webmvc 6.2.19 :347-361, WebFlux :195-204) takesrequestMappings.get(0)and logs "Multiple @RequestMapping annotations found on …, but only the first will be used".Probe on 6.2.19 and 7.0.9 (MVC and WebFlux gave identical results):
@ApiGet(aliaspathdefault/items), class/apiGET /api/items@GetMapping("/a") @PostMapping("/b")GET /api/aonly — reversed order:POST /api/bonly@RequestMapping("/d")+@ApiGet, both source orders/d; the composedGETis ignoredpathSo: one annotation wins (a direct
@RequestMappingfirst, else the nearest composed one, ties by source order), and everyattribute — path, verbs,
produces,consumes— comes from that winner. Nothing is folded in from the losers.What changed
HandlerMethods.methodMapping(member, mah)is now the single reader: it picks the winner withMetaAnnotationsHolder.nearestAnnotation, reads merged values, and falls back to declared PSI values when there is no UASTelement, exactly as
requestMappingPrefixesdoes for the class level (#690). Every caller delegates to it:SpringWebUtil.requestMappingOfandgetEndpointInfo,ControllerEndpointActionsLineMarkerProvider,EndpointRunLineMarkerProvider,RequestMappingDuplicateInspectionand the MCPSpringMcpProvider.mediaTypesOf, which had thesame union defect for
produces/consumes.User-visible removal: where a method carried several mapping annotations, the Endpoints tool window and the MCP tools listed
a row per combination. They now list the one route Spring serves. A follow-up inspection ("several mappings on one element, only
the first is used") is worth filing separately.
Two smaller things in the same area:
@GetMapping(SOME_UNRESOLVED_CONST)) no longer becomes a phantom row at the class prefix.""now means "this mapping declares no path", which is what it meant before this PR; an unreadable one yields no row.RequestMappingVisitorinRequestMappingDuplicateInspectionis deleted. It had no caller and never had one(
git log -Sover the constructor call is empty; onlycheckClassis overridden), so it was dead code that this PR wouldotherwise have carried forward in rewritten form.
Known gaps (unchanged by this PR, worth their own issues)
@AliasFordefault. This is the agreed shape of the class-level reader too.method = Mwhereval M = RequestMethod.GET) is named after the constant. Pre-existing inevery reader.
getEndpointInfostill fall back to the class prefix for a declared-but-unreadable path; they did so beforethis PR as well (
…mapNotNull{…}.firstOrNull() ?: ""onmain).Tests
Red first:
loader/{java,kotlin}/ComposedMethodMappingTest.kt+ComposedMethodMappingFixture.ktand two cases ininspections/{java,kotlin}/RequestMappingDuplicateInspectionTest.kt— 30 of 48 failing on the pre-fix head, with the Spring 7classes and the use-site-alias cases green as controls. The fixtures mirror the probe sources, including both source orders.
Verification on the final head: target classes 54 tests, 0 failures; spring-web
loader.*+providers.*+inspections.*708 tests, 0 failures;
spring-aimcp.*793 tests, 0 failures (one Exodus thread-leak flake in the batch run passedwhen the class was rerun alone).
Backport
Main-only:
HandlerMethods,MergedAnnotationAttributesandnearestAnnotationexist on norelease/*branch.