Skip to content

SONARJAVA-7255 Convert the PSI syntax tree to the Sonar AST - #6424

Closed
aurelien-coet-sonarsource wants to merge 1 commit into
ac/java-psi-frontendfrom
ac/java-psi-frontend-1
Closed

aurelien-coet-sonarsource wants to merge 1 commit into
ac/java-psi-frontendfrom
ac/java-psi-frontend-1

Conversation

@aurelien-coet-sonarsource

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

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • PSI syntax conversion:
    • Added PsiTreeConverter to map IntelliJ PSI trees onto the existing Sonar syntax model
    • Added PsiTokenIndex and PsiSourceSnapshot to track tokens, comments, and Unicode escape offsets
  • Build and packaging:
    • Added IntelliJ PSI dependencies to java-frontend/pom.xml with transitive dependencies excluded
    • Updated shading filters, jar size bounds, and license config in sonar-java-plugin/pom.xml
  • Parser refactor:
    • Moved parent wiring from JParser into new JavaTreeFinalizer and made KeywordThis and KeywordSuper public
  • Tests:
    • Added PSI test harness, stub factories, and converter tests comparing output against ECJ syntax trees
  • Runtime bootstrap:
    • Added JavaPsiApplication to register IntelliJ core extensions and services for PSI parsing

This will update automatically on new commits.

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Convert the PSI syntax tree to the Sonar AST SONARJAVA-7255 Convert the PSI syntax tree to the Sonar AST Oct 28, 2026
@hashicorp-vault-sonar-prod

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

Copy link
Copy Markdown
Contributor

SONARJAVA-7255

@datadog-sonarsource

datadog-sonarsource Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Pipelines

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 3 Pipeline jobs failed

Build | Build and Unit Test on Windows — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

Build | Build

View more details · View in GitHub Actions

Build | Ruling Update and Notify

View more details · View in GitHub Actions

Useful? React with 👍 / 👎

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

Comment thread sonar-java-plugin/pom.xml Resolved
Comment on lines +53 to +61
@AfterAll
static void close() {
if (session != null) {
session.close();
}
var expected = java.util.EnumSet.allOf(Tree.Kind.class);
expected.remove(Tree.Kind.OTHER);
assertThat(observedKinds).containsAll(expected);
}

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: @afterall kind-coverage assertion fails any partial test run

PsiTreeConverterTest.close() asserts that observedKinds contains every Tree.Kind except OTHER. observedKinds is filled as a side effect of whichever compare calls happened to run in that JVM. If you run one test method or one parameterized case on its own (e.g. -Dtest=PsiTreeConverterTest#module_declarations, or rerunning a single failure from the IDE), the class fails in @AfterAll even though the selected test passed. The failure is also reported against the class rather than the test that caused it. Moving the coverage check into its own @Test that converts a fixed corpus would make each test independent.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
CI failed: Three CI failures: a PsiTreeConverterTest NullPointerException in java-frontend (change-related, high confidence), a license-maven-plugin download failure for 21 artifacts including java-frontback-psi (relationship to PR unclear), and a skipped ruling QA prerequisite breaking the ruling update job (unrelated to PR).

Overview

Three unique error templates were analyzed across 8 logs for commit 02a60f3. One failure is directly tied to the PR's new PSI-to-AST test, one is a dependency/license issue whose relation to the PR is unclear, and one is an unrelated workflow configuration problem.

Failures

Test NullPointerException in PsiTreeConverterTest (confidence: high)

  • Type: test
  • Affected jobs: 122927260075 (Windows java-frontend build)
  • Related to change: yes
  • Root cause: PsiTreeConverterTest.mapping_inventory_covers_the_ecj_converter threw java.lang.NullPointerException from Objects.requireNonNull at PsiTreeConverterTest.java:386. The log does not show which value was null. The reactor then skipped downstream modules. Surefire reported 905 tests in that class with 1 error, and the module reported 2964 tests run, 1 error.
  • Suggested fix: Inspect the expression passed to Objects.requireNonNull at java-frontend PsiTreeConverterTest.java:386. Make sure the expected ECJ-to-PSI mapping or resource is available to the inventory check, or handle its absence with an explicit assertion. Then rerun the java-frontend test suite.

License download failure for 21 artifacts, including java-frontback-psi (confidence: high)

  • Type: dependency
  • Affected jobs: 122925681789 (Linux sonar-java-plugin build)
  • Related to change: unclear
  • Root cause: license-maven-plugin:download-licenses reported no license information for com.jetbrains.intellij.java:java-frontback-psi:262.10968.63 and 20 other artifacts, failing the sonar-java-plugin module. The supplied change context does not include the POM edits, so it is not established whether this dependency was newly added by the PR.
  • Suggested fix: Review sonar-java-plugin/target/generated-resources/licenses-errors.xml for all 21 artifacts. Provide or configure license metadata for the affected dependencies, including java-frontback-psi, then rerun the license goal and build. If the dependency was added in this PR, that is the likely link to the change.

Ruling update job failed after ruling QA was skipped (confidence: high)

  • Type: configuration
  • Affected jobs: 122927260075 (Ruling Update and Notify)
  • Related to change: no
  • Root cause: needs.ruling-qa.result was skipped, so ruling-failed=true was set. The update action then failed with No artifacts were downloaded (directory does not exist). The log does not show why ruling QA was skipped.
  • Suggested fix: Make the update-and-notify step tolerate a skipped ruling QA job without attempting artifact sync, or ensure the prerequisite job runs and uploads the expected actual_* artifacts. Investigate the upstream skip condition separately.

Summary

  • Change-related failures: 1 (PsiTreeConverterTest NullPointerException in java-frontend, which is part of the new PSI conversion code).
  • Infrastructure/flaky failures: 0 confirmed. The ruling job failure is a workflow configuration issue, not flaky infrastructure.
  • Unclear relationship: 1 (license download failure for 21 artifacts, including java-frontback-psi; the PR may have added this dependency, but the POM diff is not in the context).
  • Unrelated: 1 (ruling update job failure caused by a skipped prerequisite).
  • Recommended action: Fix the NullPointerException in PsiTreeConverterTest.java:386 first, since it blocks the java-frontend module and downstream modules. Next, confirm whether java-frontback-psi was added by this PR and supply license metadata or an exclusion. Triage the ruling workflow separately.
Code Review 👍 Approved with suggestions 1 closed / 2 findings

🟡 Medium risk · Adding a PSI-to-Sonar AST conversion path and IntelliJ runtime dependencies could affect syntax-tree interpretation and Java analysis results.

Adds PsiTreeConverter and PSI token/source tracking to map IntelliJ PSI trees onto the Sonar AST, with build, packaging, and bootstrap wiring for the IntelliJ core. The license config issue that failed validation is resolved. Consider moving the PsiTreeConverterTest kind-coverage check from @AfterAll into its own @Test so a single test run does not fail the class.

💡 Quality: @AfterAll kind-coverage assertion fails any partial test run

📄 java-frontend/src/test/java/org/sonar/java/model/psi/PsiTreeConverterTest.java:53-61

PsiTreeConverterTest.close() asserts that observedKinds contains every Tree.Kind except OTHER. observedKinds is filled as a side effect of whichever compare calls happened to run in that JVM. If you run one test method or one parameterized case on its own (e.g. -Dtest=PsiTreeConverterTest#module_declarations, or rerunning a single failure from the IDE), the class fails in @AfterAll even though the selected test passed. The failure is also reported against the class rather than the test that caused it. Moving the coverage check into its own @Test that converts a fixed corpus would make each test independent.

✅ 1 closed
✅ Bug: License config file and new third-party licenses missing; validation fails

📄 sonar-java-plugin/pom.xml:302 📄 java-frontend/pom.xml:27-41
sonar-java-plugin/pom.xml now sets <licensesConfigFile>${project.basedir}/license-resources/licenses.xml, but this PR doesn't add that file. license-resources/ only holds LicenseValidator.java, README.md, bsd.txt, epl.txt and lgpl.txt. So whatever license overrides were meant for the IntelliJ/Kotlin artifacts don't exist.

The new java-frontend compile dependencies (kotlin-stdlib, kotlinx-coroutines, kotlinx-collections-immutable, intellij-deps-fastutil, opentelemetry-api, and the com.jetbrains.intellij.* artifacts) get bundled into the plugin. None of their license files were committed under src/main/resources/licenses/THIRD_PARTY_LICENSES.

The validate-license-files execution runs by default in the verify phase. It compares the downloaded temp-licenses directory against the committed directory and exits 1 when there are new files, so a normal mvn verify of sonar-java-plugin should fail. To fix it, commit license-resources/licenses.xml (or remove the reference) and regenerate the committed licenses with -PupdateLicenses.

🤖 Prompt for agents
Code Review: Adds `PsiTreeConverter` and PSI token/source tracking to map IntelliJ PSI trees onto the Sonar AST, with build, packaging, and bootstrap wiring for the IntelliJ core. The license config issue that failed validation is resolved. Consider moving the `PsiTreeConverterTest` kind-coverage check from `@AfterAll` into its own `@Test` so a single test run does not fail the class.

1. 💡 Quality: @AfterAll kind-coverage assertion fails any partial test run
   Files: java-frontend/src/test/java/org/sonar/java/model/psi/PsiTreeConverterTest.java:53-61

   `PsiTreeConverterTest.close()` asserts that `observedKinds` contains every `Tree.Kind` except `OTHER`. `observedKinds` is filled as a side effect of whichever `compare` calls happened to run in that JVM. If you run one test method or one parameterized case on its own (e.g. `-Dtest=PsiTreeConverterTest#module_declarations`, or rerunning a single failure from the IDE), the class fails in `@AfterAll` even though the selected test passed. The failure is also reported against the class rather than the test that caused it. Moving the coverage check into its own `@Test` that converts a fixed corpus would make each test independent.

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

Functional validation No results

Rules 2 passed 1 not applicable

✅ Internal artifact registries
✅ Repository license compliance

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

SonarSource/sonar-java-symbolic-execution Inspected
SonarSource/sonarqube Inspected

Cross-PR 1 PR inspected 0 open impacts

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.

Tip

Comment Gitar fix CI or enable auto-apply: gitar auto-apply:on

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

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