Skip to content

SONARJAVA-7253 Do not run Spring context collection in SonarLint or in projects without Spring dependencies - #6423

Merged
aurelien-coet-sonarsource merged 3 commits into
masterfrom
ac/SONARJAVA-7253
Oct 28, 2026
Merged

aurelien-coet-sonarsource merged 3 commits into
masterfrom
ac/SONARJAVA-7253

Conversation

@aurelien-coet-sonarsource

@aurelien-coet-sonarsource aurelien-coet-sonarsource commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Spring context gating:
    • Enabled Spring context collection only when Spring dependencies are detected outside SonarLint
    • Moved SpringContextModelSensor to run after JavaSensor, skipping execution in SonarLint or when collection is disabled
  • Dependency detection:
    • Extracted hasSpringDependency into SpringContextModelGatherers and reused it from gatherers
  • Persistence:
    • Model restoration is deferred until Spring dependencies are found; the enabled flag is not persisted
  • Gatherer registration:
    • Spring gatherers are added to JavaSensor main checks at analysis time instead of being registered in its constructor
  • Tests:
    • Added unit and integration tests for non-Spring projects and SonarLint behavior

This will update automatically on new commits.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7253

@datadog-sonarsource

datadog-sonarsource Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 888307b | Docs | Give us feedback!

@aurelien-coet-sonarsource
aurelien-coet-sonarsource marked this pull request as ready for review October 28, 2026 13:07

@asya-vorobeva asya-vorobeva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also makes sense to clarify with user inhttps://community.sonarsource.com/t/sonarqube-for-ide-creates-sonar-spring-context-model-json-in-every-analyzed-module-in-eclipse/190547/6 how they analyze the project and understand why multiple files are created.

}
SonarComponents components = createSonarComponentsMock(context);
if (sonarLint) {
when(components.getJavaClasspath()).thenReturn(TestClasspathUtils.DEFAULT_MODULE.getClassPath());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in the same block as context.setRuntime(TestSonarRuntime.forSonarLint...)

void spring_context_model_is_reported_as_telemetry() {
var project = analyzeProject(Path.of("ambiguous-dependencies-should-be-resolved"), "S9352").getProject();

assertThat(projectBaseDir.resolve(".sonar/spring-context-model.json")).exists();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add checks that such files aren't created for sub-modules.

@aurelien-coet-sonarsource

Copy link
Copy Markdown
Contributor Author

Also makes sense to clarify with user inhttps://community.sonarsource.com/t/sonarqube-for-ide-creates-sonar-spring-context-model-json-in-every-analyzed-module-in-eclipse/190547/6 how they analyze the project and understand why multiple files are created.

Yes, I've asked for more details here.

@gitar-bot

gitar-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Gating Spring context collection on detected dependencies and product could omit context-based findings or saved models when Spring dependencies are missed.

Gates Spring context collection so it only runs outside SonarLint and in projects with Spring dependencies, moving SpringContextModelSensor after JavaSensor. No issues found.

Verification Rules 1/1 met PRs 2 inspected

Functional validation No results

Rules 1 passed 2 not applicable

✅ Repository license compliance

Broader impact PRs 2 inspected
Cross-PR 2 PRs inspected 0 open impacts

PR 6394: SONARJAVA-7229 Add telemetry for Java semantic degradation and classpath configuration Inspected
PR 6416: SONARJAVA-7252 Decouple the Java frontend from Eclipse JDT core Inspected

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

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

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

@asya-vorobeva asya-vorobeva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@aurelien-coet-sonarsource
aurelien-coet-sonarsource merged commit ffd7b11 into master Oct 28, 2026
20 checks passed
@aurelien-coet-sonarsource
aurelien-coet-sonarsource deleted the ac/SONARJAVA-7253 branch October 28, 2026 15:02
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.

2 participants