Repository navigation
SONARJAVA-6419 Use the Spring context model in S4605 to make it cross-module - #6376
Conversation
…-module Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Ruling Diff SummaryDetected changes in 1 rule files: 3 issues removed, 0 issues added. S4605 (
|
…ation A @componentscan declared directly on a class shadows the one @SpringBootApplication contributes as a meta-annotation, so Spring honours only the former. The gatherer collected both, widening the scanned package set with scanBasePackages that Spring ignores. Gate @SpringBootApplication on the whole annotation instead of only on the own-package fallback. The decision is now taken per class rather than from the packages collected so far in the file, so it no longer depends on the order in which classes of a file are visited.
d8af427 to
88e4f37
Compare
Code Review ✅ Approved 2 closed / 2 findings🟡 Medium risk · Cross-module S4605 scan aggregation and bean-kind filtering could misreport reachable beans or miss genuinely unreachable ones. Moves ✅ 2 closed✅ Edge Case: Direct @componentscan without base packages doesn't shadow @SpringBootApp
Closed: Quality: Cache entry shape changed without bumping CACHE_FORMAT_VERSION
Verification Rules 2/2 met Knowledge ✅ 1 Repos 6 inspected · PRs 2 inspectedFunctional validation No results Rules 2 passed 1 not applicable
Broader impact Repos 6 inspected PRs 2 inspectedCross-repo 6 repositories inspected 0 open impacts
1 more repository Cross-PR 2 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
aurelien-coet-sonarsource
left a comment
There was a problem hiding this comment.
Just a small suggestion, but LGTM ! 👍
|
|
||
| // @ComponentScan without explicit packages shadows @SpringBootApplication's ones. | ||
| @SpringBootApplication(scanBasePackages = "x") | ||
| @ComponentScan(excludeFilters = @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.example.excluded")) |
There was a problem hiding this comment.
We don't do anything with the filter on the component scan annotation here, right ? Maybe we should remove it to avoid confusion ?
There was a problem hiding this comment.
No, here no, but we have a ticket to fix this (I've created it some time ago, even before working on Spring Context Model). I'd prefer to deliberately leave it here as a mention.
There was a problem hiding this comment.
Ok, makes sense then. Thanks for the link !




Also refactored tests to use common helper class for SpringContextModel-based checks.
Summary by Gitar
SpringBeansShouldBeAccessibleCheckontoSpringContextModel, so it detects uncovered beans across modulesSpringContextChecksso it runs during analysisBeanDefinitionKindto separate stereotype, configuration, and factory method beans@SpringBootApplicationnow collects the empty package, which covers all packages@ComponentScanon a class now shadows the one@SpringBootApplicationcontributesSpringContextModelTestUtilsused by the S4605 and AmbiguousDependency testsOtherComponentin moduleBkindin the Spring context model JSON throughBeanDefinitionHolderTypeAdapterThis will update automatically on new commits.