Skip to content

SONARJAVA-7197 Log when no Spring context model file is found at the start of an analysis - #6366

Open
aurelien-coet-sonarsource wants to merge 3 commits into
masterfrom
ac/spring-logs
Open

aurelien-coet-sonarsource wants to merge 3 commits into
masterfrom
ac/spring-logs

Conversation

@aurelien-coet-sonarsource

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

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Logging:
    • Added a warning when the Spring context model file is missing, noting analysis starts with an empty context
    • Added an info log when the Spring context model is restored from file, including module, bean, and package counts

This will update automatically on new commits.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Log when no Spring context model file is found at the start of an analysis SONARJAVA-7197 Log when no Spring context model file is found at the start of an analysis Oct 15, 2026
@hashicorp-vault-sonar-prod

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

Copy link
Copy Markdown
Contributor

SONARJAVA-7197

Comment on lines 50 to 52
if (!Files.exists(path)) {
LOG.warn("Spring context model file does not exist: {}. Starting with an empty Spring context.", path);
return new SpringContextGatheringModel();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: WARN fires on every first analysis and every non-Spring Java project

JavaSensor.execute calls SpringContextModelPersistence.load(path) on every Java analysis, with nothing checking whether the project uses Spring. The default path is .sonar/spring-context-model.json, which won't exist on a project's first analysis, on CI agents that don't cache .sonar/, or for any project where the model was never written. In all of those cases the new line logs at WARN even though nothing is wrong, so users see warnings they can't act on and real warnings get harder to spot. Log this expected state at INFO or DEBUG. Keep WARN for the read/parse failure branch below, which is a real problem.

Log the missing file, which is expected, at INFO (or DEBUG) instead of WARN.:

LOG.info("Spring context model file does not exist: {}. Starting with an empty Spring context.", path);
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 closed / 1 findings

🟢 Low risk · Adds diagnostic logs for missing or restored Spring context models; restoration behavior remains unchanged, limiting impact to analysis output.

Adds logging around Spring context model loading at analysis start, including a warning when the model file is missing and an info log on successful restore. Consider lowering the missing-file message from WARN to INFO or DEBUG, since first analyses and non-Spring projects will hit it routinely and the WARN would be noise; keep WARN for read/parse failures.

💡 Quality: WARN fires on every first analysis and every non-Spring Java project

📄 sonar-java-plugin/src/main/java/org/sonar/plugins/java/SpringContextModelPersistence.java:50-52

JavaSensor.execute calls SpringContextModelPersistence.load(path) on every Java analysis, with nothing checking whether the project uses Spring. The default path is .sonar/spring-context-model.json, which won't exist on a project's first analysis, on CI agents that don't cache .sonar/, or for any project where the model was never written. In all of those cases the new line logs at WARN even though nothing is wrong, so users see warnings they can't act on and real warnings get harder to spot. Log this expected state at INFO or DEBUG. Keep WARN for the read/parse failure branch below, which is a real problem.

Log the missing file, which is expected, at INFO (or DEBUG) instead of WARN.
LOG.info("Spring context model file does not exist: {}. Starting with an empty Spring context.", path);
🤖 Prompt for agents
Code Review: Adds logging around Spring context model loading at analysis start, including a warning when the model file is missing and an info log on successful restore. Consider lowering the missing-file message from WARN to INFO or DEBUG, since first analyses and non-Spring projects will hit it routinely and the WARN would be noise; keep WARN for read/parse failures.

1. 💡 Quality: WARN fires on every first analysis and every non-Spring Java project
   Files: sonar-java-plugin/src/main/java/org/sonar/plugins/java/SpringContextModelPersistence.java:50-52

   `JavaSensor.execute` calls `SpringContextModelPersistence.load(path)` on every Java analysis, with nothing checking whether the project uses Spring. The default path is `.sonar/spring-context-model.json`, which won't exist on a project's first analysis, on CI agents that don't cache `.sonar/`, or for any project where the model was never written. In all of those cases the new line logs at WARN even though nothing is wrong, so users see warnings they can't act on and real warnings get harder to spot. Log this expected state at INFO or DEBUG. Keep WARN for the read/parse failure branch below, which is a real problem.

   Fix (Log the missing file, which is expected, at INFO (or DEBUG) instead of WARN.):
   LOG.info("Spring context model file does not exist: {}. Starting with an empty Spring context.", path);

Verification Rules 1/1 met Repos 2 inspected · PRs 1 inspected

Functional validation No results

Rules 1 passed 2 not applicable

✅ Repository license compliance

Broader impact Repos 2 inspected PRs 1 inspected
Cross-repo 2 repositories inspected 0 open impacts

SonarSource/sonarlint-language-server Inspected
SonarSource/sonarlint-vscode Inspected

Cross-PR 1 PR inspected 0 open impacts

PR #6306: [DO NOT MERGE] Add project-wide semantic analysis report 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

This branch has not been deployed

No deployments
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