Skip to content

JAVA-7395 Run a SemSitter parsing session - #6569

Open
rombirli wants to merge 2 commits into
rombirli/semsitter-protocol-clientfrom
rombirli/semsitter-parsing-session
Open

rombirli wants to merge 2 commits into
rombirli/semsitter-protocol-clientfrom
rombirli/semsitter-parsing-session

Conversation

@rombirli

@rombirli rombirli commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Part 3 of 17 of JAVA-7392. Ticket: JAVA-7395.

Intent

SemSitterParser is a JParser that runs one SemSitter server per parse call and hands each file's document to a DocumentTranslator. Nothing creates it yet.

It never hands a file to ECJ: the two frontends stay independent, so a comparison between them means something.

flowchart TD
  P[parse files] --> S{server starts and accepts settings?}
  S -->|no| E1[IllegalStateException: analysis fails]
  S -->|yes| F[for each file: get-file, translate]
  F -->|tree| OK[result]
  F -->|UnsupportedConstructException| U[parse error for this file]
  F -->|syntax error| R[parse error at its position]
  F -->|IO or runtime failure| X[parse failure for this file only]
Loading
} catch (UnsupportedConstructException unsupported) {
  return JParseResult.failure(new RecognitionException(0, unsupported.getMessage(), unsupported));
}

A file the translator does not support yet shows up like a file ECJ cannot parse: logged, counted as a parse error, and the analysis goes on.

  • ParseProgress: ProgressReport file by file; in batch mode the shared AnalysisProgress drives the logs, like the ECJ batch parser (start on the first batch, global percentage, done on the last)
  • SessionTypes: every type declaration the server sends is kept once for the whole session
  • DocumentTranslator.ServerLoaders: types and package lookups, answering null once the server is closed
  • ProjectRoot and SemSitterSettings: server root and settings from the analysis configuration

State on master

The plugin never creates a SemSitterParser. ECJ parses exactly as today.

Test plan

  • SemSitterParserTest with a scripted server: start failures fail the analysis, unsupported files are parse errors, batch progress, cancellation and loader failures
  • SessionTypesTest, ProjectRootTest, SemSitterSettingsTest

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

JAVA-7395

@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 9324d80 to 276b0d1 Compare November 25, 2026 10:04
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 276b0d1 to 85cb5f9 Compare November 25, 2026 10:05
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 85cb5f9 to 352faee Compare November 25, 2026 10:11
@rombirli
rombirli added this pull request to stack #6570 November 25, 2026 10:36
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 352faee to 8104259 Compare November 25, 2026 10:41
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 8104259 to 3701c29 Compare November 25, 2026 12:00
@rombirli rombirli changed the title JAVA-7395 Run a SemSitter parsing session with a per-file ECJ fallback JAVA-7395 Run a SemSitter parsing session with an ECJ fallback Nov 25, 2026
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 3701c29 to 2ba4d26 Compare November 25, 2026 12:03
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 2ba4d26 to 402a1ea Compare November 25, 2026 16:31
@rombirli rombirli changed the title JAVA-7395 Run a SemSitter parsing session with an ECJ fallback JAVA-7395 Run a SemSitter parsing session Nov 25, 2026
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 402a1ea to 50f8e2c Compare November 25, 2026 17:16
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 50f8e2c to fecc6b9 Compare November 25, 2026 20:45
@rombirli
rombirli removed this pull request from stack #6570 November 25, 2026 20:47
@rombirli
rombirli added this pull request to stack #6589 November 25, 2026 20:48
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from fecc6b9 to 7c80bb5 Compare November 27, 2026 07:55
@rombirli
rombirli force-pushed the rombirli/semsitter-parsing-session branch from 7c80bb5 to 62b1b80 Compare November 27, 2026 09:24
@gitar-bot

gitar-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown
CI failed: The Ruling Update and Notify job failed because the Ruling QA job was cancelled and produced no actual_* artifacts to download. The cancellation cause is not shown in the logs, and the analyzer marked the failure as unrelated to this PR, so it is not attributed to the SemSitter parsing change.

Overview

The Ruling Update and Notify job failed because the Ruling QA job was cancelled and produced no actual_* artifacts to download. The cancellation cause is not shown in the logs, and the analyzer marked the failure as unrelated to this PR, so it is not attributed to the SemSitter parsing change.

Failures

Ruling Update and Notify failed after Ruling QA cancellation left no artifacts (unrelated to PR)

  • Type: infrastructure
  • Affected jobs: 140420189080
  • Related to change: no
  • Confidence: high
  • Root cause: The log reports ruling-qa.result as cancelled, then the ruling update action fails with No artifacts were downloaded (directory does not exist). The reason QA was cancelled is not shown. The PR adds SemSitter parsing functionality, but the supplied evidence does not connect those changes to the cancellation or the downstream artifact-download failure.
  • Suggested fix: Determine why the Ruling QA job was cancelled and rerun it so it can upload the expected artifacts. If cancellation is an expected outcome, update the ruling notification workflow to handle missing artifacts without failing.

Summary

  • Change-related failures: 0
  • Infrastructure/flaky failures: 1
  • Recommended action: Determine why the Ruling QA job was cancelled and rerun it so it can upload the expected artifacts. If cancellation is an expected outcome, update the ruling notification workflow to handle missing artifacts without failing.
Code Review ✅ Approved 🟡 Medium risk 6 closed / 6 findings

The standalone SemSitter parser is not yet wired into the plugin, but when adopted its translation and server-failure handling could change parse outcomes.

Adds SemSitterParser, which runs one SemSitter server per parse call and translates each file's document, reporting unsupported files as parse errors rather than handing them to ECJ. One open minor issue: the UnsupportedConstructException javadoc still says unsupported files fall back to the default frontend, which contradicts the parse-error behaviour and should be corrected. Resolved this session: files on different roots no longer crash parsing instead of falling back, and FILE_BY_FILE cancellation now reports progress as completed.

✅ 6 closed
✅ Edge Case: Files on different roots crash parse instead of falling back to ECJ

📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ProjectRoot.java:45-51 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/ProjectRoot.java:56-58 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:99-101 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:158
When the files share no directory (Windows sources on two drives, or a mix of UNC and local paths), shared returns first.getRoot(), e.g. C:\. ProjectRoot.relative then calls C:\.relativize(D:\...), and Path.relativize throws IllegalArgumentException for paths with different roots. The first such call is the sort comparator at SemSitterParser.java:100, which runs before open() and outside its try/catch. The exception escapes parse and breaks the analysis. The PR promises that every failure mode ends on ECJ or on a per-file parse error, so this case should fall back. Fix: if any file is not under root, hand all files to fallback, or move the root computation and the sort inside the guarded section.

✅ Quality: FILE_BY_FILE cancellation reports the progress as completed

📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:116-130
In FILE_BY_FILE mode a cancellation runs break, then completed = true is set, so the finally block calls progressReport.stop() instead of cancel(). ProgressReport then logs a normal "N/M files have been analyzed" completion for a run that was cancelled. JDTParser.FileByFile, the frontend this parser replaces, sets successfullyCompleted = !cancelled so that a cancelled run calls progressReport.cancel(). Fix: track cancellation and set completed only when the loop ran through every file.

Closed: Cross-PR: #6553's translator stops compiling against the 4-arg DocumentTranslator

📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/DocumentTranslator.java:31 📄 java-frontend-semsitter/src/test/java/org/sonar/java/semsitter/SemSitterParserTest.java:301
Breaks when this PR merges first and #6553 is then rebased onto a branch that contains it, so both land in the same java-frontend-semsitter module.

How

  1. This PR declares translate(Document, ServerLoaders, boolean, int) at DocumentTranslator.java:31, and its tests use that shape (SemSitterParserTest.java:301).
  2. SONARJAVA-7339 Parse with the SemSitter translator behind the feature flag #6553 keeps translate(Document, Function<Set<String>,JsonObject>, Function<String,Boolean>, boolean, int) in its DocumentTranslator, and SemSitterTranslator.translate at SemSitterTranslator.java:197 has that 5-argument signature.
  3. SONARJAVA-7339 Parse with the SemSitter translator behind the feature flag #6553's SemSitterParser.java:184 calls translator.translate(document, this::types, this::hasPackage, noLibraries, javaVersion), and its provider binds SemSitterTranslator::translate. Neither matches the 4-argument interface, so the build fails.
  4. SONARJAVA-7339 Parse with the SemSitter translator behind the feature flag #6553 has no UnsupportedConstructException, so its translator can't trigger the per-file ECJ fallback that this PR's SemSitterParser catch block depends on.

Fix

Compared 85cb5f9 with #6553 at ae4a758

Closed: Quality: Per-file fallback runs a full JParser.parse, logging and set-up per file

📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:186-193
PerFileFallback.parse (SemSitterParser.java:186-193) sends each unsupported file to JParser.parse(List.of(file), () -> false, new AnalysisProgress(1), ...) on its own. That method brings the parser's whole per-call machinery with it. With a FILE_BY_FILE JDTParser (JDTParser.java:251-276), every unsupported file starts a new ProgressReport thread. Each one logs "1 source file to be analyzed" and "1/1 source file has been analyzed" at INFO, plus its own ExecutionTimeReport, while the outer SemSitter ProgressReport is still running. With a BATCH JDTParser (JDTParser.java:187-229), each file gets a fresh ASTParser/createASTs environment over the full classpath and a ProgressMonitor thread. new AnalysisProgress(1) counts as the first batch, so that monitor logs "Starting batch processing." for every file (ProgressMonitor.java:94-95). Early translator slices will throw UnsupportedConstructException for most files, so this floods the logs and repeats the ECJ setup once per file. Caching the JParser instance does not avoid the setup, because JDTParser builds a new ASTParser on every parse call. Fix: give the per-file path a quiet single-file entry point, such as a package-visible parse(InputFile) on the default frontend, or collect the unsupported files and parse them in one fallback call at the end.

Closed: Quality: BATCH mode ignores AnalysisProgress, reporting progress per batch

📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:93 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:111 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:114-117
JavaFrontend.scanBatch calls the parser once per batch and passes a shared AnalysisProgress, so the ECJ batch parser can log global progress across batches. Its ProgressMonitor logs the start only on the first batch and "100% analyzed" only on the last. SemSitterParser.parse accepts analysisProgress but never passes it to scan (SemSitterParser.java:93-112, 114-148). In BATCH mode it starts a new ProgressReport on every call, so each batch logs its own "N source files to be analyzed" and "N/N ... analyzed" lines, and the global percentage is lost. Fix: in BATCH mode, drive progress from analysisProgress (for example toGlobalPercentage, with start and end logs gated on isFirstBatch/isLastBatch) and keep ProgressReport for FILE_BY_FILE.

...and 1 more closed from earlier reviews

Verification Rules 3/3 met Repos 3 inspected · PRs 3 inspected

Functional validation No results

Rules 3 passed 2 not applicable

✅ Internal artifact registries
✅ Release secrets usage
✅ Repository license compliance

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

SonarSource/sonar-iac Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarlint-eclipse Inspected

Cross-PR 3 PRs inspected 0 open impacts

PR 6573: JAVA-7396 Add the SemSitter semantic model of types, symbols and members Inspected
PR 6575: JAVA-7398 Translate SemSitter documents into the Java syntax tree Inspected
PR 6583: JAVA-7406 Offer the SemSitter frontend behind a flag 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

@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