Skip to content

SONARJAVA-7297 Decouple Problems and Warnings from Eclipse JDT core specifics - #6479

Merged
aurelien-coet-sonarsource merged 3 commits into
masterfrom
ac/implementation-agnostic-frontend-1
Nov 6, 2026
Merged

aurelien-coet-sonarsource merged 3 commits into
masterfrom
ac/implementation-agnostic-frontend-1

Conversation

@aurelien-coet-sonarsource

@aurelien-coet-sonarsource aurelien-coet-sonarsource commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • New diagnostics API:
    • Added Problem, Warning, and ProblemKind interfaces under org.sonar.plugins.java.api.diagnostics, decoupling problems from Eclipse JDT types
    • Exposed semanticProblems(), supportedWarningKinds(), and warnings(ProblemKind) on CompilationUnitTree
  • Refactored checks:
    • Migrated UselessImportCheck, RedundantTypeCastCheck, SelfAssignmentCheck, and UnreachableCatchCheck to use the new API instead of JWarning/JProblem.Type
  • Frontend internals:
    • Replaced JProblem.Type enum with ProblemKind mapping from ECJ problem IDs, and moved undefined-type collection in SonarComponents to a ProblemKey record
    • Changed UselessImportCheck to derive import names from the syntax tree instead of parsing ECJ messages
  • Behavior fixes:
    • Warning end positions use the problem's source end offset
    • Parenthesized redundant-cast warnings resolve to the cast in JWarning.Mapper
    • Preview feature messages are normalized in the JProblem constructor
    • Switch-expression yield missing-default problems are no longer treated as syntax errors
  • Symbol-based tree model:
    • Trees store Symbol and Type instead of ECJ bindings

This will update automatically on new commits.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Decouple Problems and Warnings from Eclipse JDT core specifics SONARJAVA-7297 Decouple Problems and Warnings from Eclipse JDT core specifics Nov 4, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-7297

@aurelien-coet-sonarsource
aurelien-coet-sonarsource force-pushed the ac/implementation-agnostic-frontend-1 branch 3 times, most recently from 7c815a7 to a4eb5fe Compare November 4, 2026 13:12
@aurelien-coet-sonarsource

Copy link
Copy Markdown
Contributor Author

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 0 new · 🗑️ 256 lost issues
View dashboard

Projects with unexpected PVF results:

  • crate

@aurelien-coet-sonarsource
aurelien-coet-sonarsource force-pushed the ac/implementation-agnostic-frontend-1 branch from a4eb5fe to a76602c Compare November 4, 2026 14:51
@aurelien-coet-sonarsource
aurelien-coet-sonarsource marked this pull request as ready for review November 4, 2026 15:12
Base automatically changed from ac/implementation-agnostic-frontend to master November 4, 2026 15:40
@aurelien-coet-sonarsource
aurelien-coet-sonarsource force-pushed the ac/implementation-agnostic-frontend-1 branch from a76602c to fff74ac Compare November 4, 2026 15:40

@rombirli rombirli 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.

LGTM, few questions regarding Beta annoration and key record

return context.config();
}

private record ProblemKey(ProblemKind type, String message) {}

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.

This tuple type/message doesn't seem unique to me, for example there can be twice the same unused import in 2 different files or even in the same file. Should we assign UUID to problems or location range to ensure uniqueness

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.

I'm asking because "Key" seems to mean they must be unique (and I see they are used as hashmaps keys)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is expected here. ProblemKey is used as the key type in SonarComponents.problemsToFilePaths, which maps problem kinds the list of files where they occur. Two different problems occurring in different files but with the same kind and message should thus share the same key, so that we can retrieve the list of files where this problem is observed.

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.

Understoood, NIT : ProblemGroupKey or ProblemBucketKey would be clearer to me

@aurelien-coet-sonarsource
aurelien-coet-sonarsource force-pushed the ac/implementation-agnostic-frontend-1 branch from 4a7a124 to c0b083d Compare November 6, 2026 09:43
@gitar-bot

gitar-bot Bot commented Nov 6, 2026

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

🟡 Medium risk · Refactoring Java diagnostics and parser classification could change which compiler warnings become issues, potentially omitting or misattributing findings.

Decouples problems and warnings from Eclipse JDT core types by introducing Problem, Warning, and ProblemKind interfaces and migrating the affected checks to the new API. Two issues were resolved: the end-position change in convert() now has test coverage, and a test stub for an unused getID() value was removed. No open findings remain.

✅ 2 closed
✅ Quality: End-position change in convert() is untested; test name says 'point'

📄 java-frontend/src/test/java/org/sonar/java/model/JWarningTest.java:47-58 📄 java-frontend/src/main/java/org/sonar/java/model/JWarning.java:124-126
This PR changes Mapper.convert to build the warning end from problem.getSourceEnd(); before, it used getSourceStart() for both ends. The new test ecj_conversion_preserves_point_locations only stubs getSourceStart() (2) and only checks start(). The unstubbed getSourceEnd() returns 0, so the warning ends at line 1, col 0, before its start at line 2. The test still passes. So the behavior change is not tested, and the name says the opposite of what the code now does. Fix: stub getSourceEnd() and assert warning.end(), and rename the test to match.

✅ Quality: Test stubs a second getID() value that convert() never reads

📄 java-frontend/src/test/java/org/sonar/java/model/JWarningTest.java:60-66 📄 java-frontend/src/main/java/org/sonar/java/model/JWarning.java:119-123
ignores_diagnostics_that_cannot_be_associated_with_supported_warning_trees stubs getID() to return ParsingError and then UndefinedType. It calls JWarning.Mapper.convert only once, and convert reads getID() only once (in JProblem.kindOf). So only the ParsingError path runs, where kindOf returns null. The UndefinedType path is never tested. That is the case where kindOf returns a non-null kind and the !WARNING_KINDS.containsKey(kind) filter has to drop it. Fix: use two separate mocks or call convert twice, and assert null each time.

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

Functional validation No results

Rules 2 passed 1 not applicable

✅ Internal artifact registries
✅ Repository license compliance

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

SonarSource/sonar-java-symbolic-execution Inspected
SonarSource/sonarlint-vscode Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarqube Inspected

Cross-PR 1 PR inspected 0 open impacts

PR 6472: SONARJAVA-7295 Decouple the frontend AST 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

@aurelien-coet-sonarsource

Copy link
Copy Markdown
Contributor Author

/pvf

@sonarqube-next

sonarqube-next Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 0 new · 🗑️ 0 lost issues
View dashboard

Projects with unexpected PVF results:

  • io.fabric8-fabric8-maven-plugin-build
  • org.apache.opennlp-opennlp
  • org.codehaus.sonar-plugins-sonar-issue-assign-plugin
  • org.codehaus.sonar-plugins-sonar-issues-report-plugin
  • org.grouplens.grapht-grapht
  • tomcat8

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 0 new · 🗑️ 0 lost issues
View dashboard

@aurelien-coet-sonarsource
aurelien-coet-sonarsource merged commit 5faffac into master Nov 6, 2026
18 checks passed
@aurelien-coet-sonarsource
aurelien-coet-sonarsource deleted the ac/implementation-agnostic-frontend-1 branch November 6, 2026 10:59
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