Skip to content

SONARJAVA-6412 Implement Visitor for grouping beans per types - #5987

Draft
NoemieBenard wants to merge 5 commits into
epic-SONARJAVA-6237from
nb/sonarjava-6412-type-to-bean-names-index
Draft

SONARJAVA-6412 Implement Visitor for grouping beans per types#5987
NoemieBenard wants to merge 5 commits into
epic-SONARJAVA-6237from
nb/sonarjava-6412-type-to-bean-names-index

Conversation

@NoemieBenard

@NoemieBenard NoemieBenard commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • New features:
    • Added TypeToBeanNamesIndexGatherer to map type hierarchies of Spring beans to bean names
  • Refactorings:
    • Extracted Spring bean and method name resolution helpers into SpringUtils
  • Tests:
    • Added comprehensive unit tests in TypeToBeanNamesIndexGathererTest covering stereotype and @Bean methods

This will update automatically on new commits.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6412

Comment thread java-frontend/src/main/java/org/sonar/java/utils/SpringUtils.java
Comment thread java-frontend/src/main/java/org/sonar/java/utils/SpringUtils.java Outdated
@NoemieBenard
NoemieBenard force-pushed the nb/sonarjava-6412-type-to-bean-names-index branch from 781a0ba to a1da0bf Compare August 21, 2026 14:12
@NoemieBenard
NoemieBenard force-pushed the nb/sonarjava-6412-type-to-bean-names-index branch from a1da0bf to c3b31d8 Compare August 21, 2026 14:30
@gitar-bot

gitar-bot Bot commented Aug 21, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 resolved / 2 findings

Implements a visitor to group Spring beans by their type and extracts resolution helpers into SpringUtils, addressing the resolveStereotypeBeanName null-guard and dropped name aliases findings.

✅ 2 resolved
Edge Case: resolveStereotypeBeanName lacks null-guard on annotation value

📄 java-frontend/src/main/java/org/sonar/java/utils/SpringUtils.java:105-109 📄 java-frontend/src/main/java/org/sonar/java/utils/SpringUtils.java:134
In SpringUtils.resolveStereotypeBeanName the stream does .map(v -> (String) v.value()) followed by .filter(s -> !s.isBlank()) with no null check, so a null annotation value would throw NPE. The sibling method resolveBeanMethodName guards this with s != null && !s.isBlank(). Although a null value is unlikely from the semantic model, make the two methods consistent by filtering nulls (e.g. .filter(s -> s != null && !s.isBlank())).

Quality: @Bean/stereotype name aliases beyond the first are dropped

📄 java-frontend/src/main/java/org/sonar/java/utils/SpringUtils.java:122-136 📄 java-frontend/src/main/java/org/sonar/java/utils/SpringUtils.java:101-115 📄 java-frontend/src/main/java/org/sonar/java/model/springcontext/TypeToBeanNamesIndexGatherer.java:55-64
resolveBeanMethodName returns only arr[0] for @Bean(name={"a","b"}), and resolveStereotypeBeanName returns a single name. Spring treats additional entries as bean aliases, so the type-to-bean-names index will not contain those aliases and lookups by an alias name will miss the bean. If alias-based resolution is in scope for this index, register all names; otherwise this is acceptable and could be documented.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown
Contributor

@datadog-sonarsource

datadog-sonarsource Bot commented Aug 21, 2026

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 21b680b | Docs | View more details | Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant