Repository navigation
Conversation
| throw new IOException("SemSitter server: " + header.get("error").getAsString()); | ||
| } | ||
| return new Answer(header, payload); | ||
| } catch (IOException e) { | ||
| String message = e.getMessage().startsWith("SemSitter") ? e.getMessage() : ("SemSitter server: " + e.getMessage()); | ||
| throw new IOException(message, e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Asks the server to quit and waits for it, forcing it to stop when it does not answer. | ||
| */ | ||
| @Override | ||
| public void close() { | ||
| try { |
There was a problem hiding this comment.
💡 Edge Case: close() can hang forever on a server that stops answering
The close() javadoc says it "forc[es] it to stop when it does not answer". In fact close() first calls send(command("quit")), which writes the request and then blocks in readLine(fromServer). That read has no timeout. If the server process is still alive but stuck (deadlock, endless loop), close() never reaches waitFor(10, SECONDS) or destroyForcibly(), so the analysis hangs inside SemSitterParser.scan's try-with-resources. Every other exchange (getFile, getTypes) also blocks with no deadline. Fix: send quit without waiting for the answer, or read the answer on a separate thread with a timeout, so the destroyForcibly fallback always runs.
Was this helpful? React with 👍 / 👎
| boolean completed = false; | ||
| try (session) { | ||
| for (InputFile file : files) { | ||
| if (isCanceled.getAsBoolean()) { | ||
| if (mode == Mode.BATCH) { | ||
| throw new CancellationException("Analysis cancelled"); | ||
| } | ||
| break; | ||
| } | ||
| executionTimeReport.start(file); | ||
| action.accept(file, session.parse(file)); | ||
| executionTimeReport.end(); | ||
| progressReport.nextFile(); | ||
| } | ||
| completed = true; |
There was a problem hiding this comment.
💡 Quality: Cancelled file-by-file parse is reported as a completed run
When isCanceled turns true in FILE_BY_FILE mode, SemSitterParser.scan breaks out of the loop and then sets completed = true. The finally block therefore calls progressReport.stop(), which reports a finished run, instead of progressReport.cancel(). ECJ's JDTParser.FileByFile tracks a separate cancelled flag and calls cancel() in this case. The PR says cancellation is "reported like ECJ", but here a cancelled analysis is logged as complete. Fix: set completed only when the loop was not broken by cancellation.
Was this helpful? React with 👍 / 👎
f908cdc to
0efff46
Compare
This comment has been minimized.
This comment has been minimized.
0efff46 to
f9667fa
Compare
| private volatile Path executable; | ||
|
|
||
| public SemSitterParserProvider() { | ||
| this(LaunchDarklyFeatureFlags::connect, System::getenv, Optional.empty()); |
There was a problem hiding this comment.
💡 Quality: Provider claims SemSitter is used but always builds the ECJ parser
After this commit the public no-arg constructor passes Optional.empty() as the translator (SemSitterParserProvider.java:59), so create() always goes through orElseGet(defaultParser) and returns JDTParser (lines 109-111). configure() still sets enabled = true and logs "The Java analyzer will use the SemSitter frontend." (lines 77-80). With sonar.java.semsitter.enabled=true or the LaunchDarkly flag on, that log is false: ECJ parses every file, and the analysis still calls the flag service for nothing. The PR description still says SemSitterTranslator/JSema translate documents, but this commit deletes them. Suggested fix: when no translator is present, keep enabled false (and skip the flag lookup), or change the log so it doesn't claim SemSitter is in use.
Only enable (and only query the flag) when a translator is available:
executable = Path.of(path.get());
if (translator.isEmpty()) {
return;
}
enabled = configuration.getBoolean(ENABLED_PROPERTY).orElseGet(() -> isFlagOn(configuration));
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
f9667fa to
4c45d27
Compare
…osen per analysis Callers keep using JParser.Mode.create. The provider is found with the ServiceLoader and falls back to the ECJ parser when none is enabled, so nothing changes until a frontend module opts in.
4c45d27 to
840aeb1
Compare
CI failed: The ruling-update job failed because the upstream ruling QA result was cancelled, so no artifacts were downloaded and the sync step errored. The analyzer attributes this to a cascading infrastructure issue, not the PR; the cause of the cancellation itself is not established by the logs.OverviewThe ruling-update job failed because the upstream ruling QA result was cancelled, so no artifacts were downloaded and the sync step errored. The analyzer attributes this to a cascading infrastructure issue, not the PR; the cause of the cancellation itself is not established by the logs. FailuresRuling-update sync failed: no artifacts after cancelled ruling QA (infrastructure, unrelated to PR)
Summary
Code Review 👍 Approved with suggestions 🔴 High risk 1 closed / 4 findingsThe selectable SemSitter frontend changes core Java parsing when enabled, so translation differences could alter findings across a project's Java files. Adds a per-analysis parser provider so the Java frontend can be switched between ECJ and SemSitter behind a feature flag, with ECJ fallback on any failure. Approved with suggestions: 💡 Edge Case: close() can hang forever on a server that stops answering📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java:180-194 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java:200-209 The 💡 Quality: Cancelled file-by-file parse is reported as a completed run📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:109-123 When 💡 Quality: Provider claims SemSitter is used but always builds the ECJ parser📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParserProvider.java:59 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParserProvider.java:77-80 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParserProvider.java:106-112 After this commit the public no-arg constructor passes Only enable (and only query the flag) when a translator is available✅ 1 closed✅ Bug: NPE when a type is looked up after the SemSitter session closes
🤖 Prompt for agentsVerification Rules 2/2 met Repos 6 inspected · PRs 3 inspectedFunctional validation No results Rules 2 passed 2 not applicable
Broader impact Repos 6 inspected PRs 3 inspectedCross-repo 6 repositories inspected 0 open impacts
1 more repository Cross-PR 3 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, comment Tip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Part of the SemSitter frontend stack: #6541, #6542, this PR.
What
Makes the Java frontend switchable between ECJ and SemSitter without touching any caller.
JParserProvider(SPI, found withServiceLoader) andJParserProviders:JParser.Mode.createnow asks the enabled provider and falls back toJDTParser.JavaSensorconfigures the providers once per analysis (not in SonarLint).SemSitterParserimplements the unchangedJParsercontract (parse(Iterable<InputFile>, BooleanSupplier, AnalysisProgress, BiConsumer<InputFile, JParseResult>)). One server per call, files parsed in the server scan order, cancellation and syntax errors reported like ECJ, fallback to ECJ if the server cannot start.SemSitterTranslator,JSemaand the symbol/type model translate the typedDocumentto the same trees and semantic model.SemSitterParserProviderenables the frontend when an executable is known (sonar.java.semsitter.executableorSEMSITTER_ANALYZER) and eithersonar.java.semsitter.enabledis set, or the LaunchDarkly flagsonar-java-semsitter-frontendis on for the project (context kindproject, keysonar.projectKey, client-side ID fromsonar.java.semsitter.launchDarkly.clientSideIdorSONAR_JAVA_LAUNCHDARKLY_CLIENT_ID). Default is off, any failure keeps ECJ.Tests
JParserProvidersTest: provider selection, fallback, failing providers.SemSitterParserProviderTest,LaunchDarklyFeatureFlagsTest(local HTTP server),SemSitterSettingsTest,ProjectRootTest,DocumentFactsTest.SemSitterParserTest: parser contract against a scripted in-memory server (ordering, settings, cancellation, fallback, syntax errors).SemSitterParityTest: parses the same sources with ECJ and a real SemSitter server and compares every node kind, position, identifier type and symbol. It only runs with-Dsemsitter.executable=<udg-java-server>.Known gaps
Parity is not complete on the check samples without a classpath. Known differences: array designators written after the name (
int f()[],String c[]), the type name of anonymous and local classes, and the naming of unresolved types. They are tracked for follow-up and do not affect the default (ECJ) path.