Skip to content

JAVA-7407 DO NOT MERGE Log how long the SemSitter graph build takes - #6610

Closed
leo-geoffroy-sonarsource wants to merge 31 commits into
rombirli/semsitter-pvffrom
lge/semsitter-pvf-udg-timing
Closed

leo-geoffroy-sonarsource wants to merge 31 commits into
rombirli/semsitter-pvffrom
lge/semsitter-pvf-udg-timing

Conversation

@leo-geoffroy-sonarsource

Copy link
Copy Markdown

Stacked on #6584. Experiment only, used to measure the UDG build in the A3S benchmarks on Dev22.

SemSitterParser now logs one INFO line each time it opens a server:

SemSitter graph of N files built in X ms (walk W ms, server start S ms, settings T ms, full-gen F ms; server-reported R ms, K failures, peak RSS M MB)
  • walk: listing the analysed files and the full sources.
  • server start, settings, full-gen: the three server requests, timed on the client.
  • server-reported, failures, peak RSS: the elapsed_ms, failures and peak_rss_kb fields of the server's full-gen answer, which the client used to drop. Shown as n/a when the server leaves them out.

To carry these fields, SemSitterApi.fullGen now returns a FullGenStats record instead of an int.

Tests: the 591 tests of org.sonar.java.semsitter pass locally (3 skipped, which need the Linux server).

🤖 Generated with Claude Code

The server now names the type of an array parameter, result or field with an
array term, java::byte[], instead of the written byte[]. Read the element of
the term so these types keep the name of the array the code declares; a hashed
term spells no element and stays unknown.
…ed fields

When the enclosing class has a supertype the server cannot read, it leaves the
names a static import brings in unresolved. Look the name up as a field of the
enclosing types first, since a declared or inherited field shadows a static
import, then as a static field of the single static import, then of each static
import on demand, as ECJ does.
SemSitterParser now logs one INFO line per server it opens, with the time
spent listing the graph files, starting the server, sending the settings
and running full-gen, plus what the server reports for full-gen: its own
elapsed time, the files it failed to scan and its peak RSS. The client
used to drop those fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Dec 2, 2026 •

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

Changing public SemSitterApi.fullGen from int to FullGenStats breaks existing callers and implementations compiled against the old signature.

Adds an INFO log line to SemSitterParser reporting how long the SemSitter graph build takes, broken down into walk, server start, settings and full-gen phases, and extends SemSitterApi.fullGen to return a FullGenStats record carrying the server's elapsed_ms, failures and peak_rss_kb values.

One open minor finding: longOrNull in SemSitterClient and SemSitterParser runs outside the exchange() try block, so a non-numeric optional measure from the server throws a raw RuntimeException instead of an IOException, which can abort the analysis. Consider parsing these measures leniently and returning null on non-numeric values, or wrapping the failure as an IOException.

💡 Edge Case: Malformed optional full-gen measure escapes as raw RuntimeException

📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java:116-125 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:169 📄 java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:177-181

longOrNull runs in fullGen after send(...) has returned, so it is outside the try in exchange() that turns runtime parse failures into IOException("SemSitter server sent a malformed answer: ..."). If the server sends a value that is not a number for elapsed_ms, failures or peak_rss_kb (for example a string like "abc", an object or an array), getAsLong() throws a raw NumberFormatException, IllegalStateException or UnsupportedOperationException. That breaks the contract that malformed answers become IOExceptions. It also means a measure that only feeds a log line aborts the whole analysis: open() wraps the exception as "The SemSitter server could not start". The fix is to parse the optional measures leniently and return null when a value is not a number, or to wrap the failure as an IOException the way exchange does.

Treat a measure that is not a number as unreported, so a diagnostic-only field cannot fail the analysis.
@Nullable
private static Long longOrNull(JsonObject header, String name) {
  JsonElement value = header.get(name);
  if (value == null || !value.isJsonPrimitive() || !value.getAsJsonPrimitive().isNumber()) {
    return null;
  }
  return value.getAsLong();
}
🤖 Prompt for agents
Code Review: Adds an INFO log line to `SemSitterParser` reporting how long the SemSitter graph build takes, broken down into walk, server start, settings and full-gen phases, and extends `SemSitterApi.fullGen` to return a `FullGenStats` record carrying the server's `elapsed_ms`, `failures` and `peak_rss_kb` values.
  
  One open minor finding: `longOrNull` in `SemSitterClient` and `SemSitterParser` runs outside the `exchange()` try block, so a non-numeric optional measure from the server throws a raw `RuntimeException` instead of an `IOException`, which can abort the analysis. Consider parsing these measures leniently and returning null on non-numeric values, or wrapping the failure as an `IOException`.

1. 💡 Edge Case: Malformed optional full-gen measure escapes as raw RuntimeException
   Files: java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterClient.java:116-125, java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:169, java-frontend-semsitter/src/main/java/org/sonar/java/semsitter/SemSitterParser.java:177-181

   `longOrNull` runs in `fullGen` after `send(...)` has returned, so it is outside the `try` in `exchange()` that turns runtime parse failures into `IOException("SemSitter server sent a malformed answer: ...")`. If the server sends a value that is not a number for `elapsed_ms`, `failures` or `peak_rss_kb` (for example a string like "abc", an object or an array), `getAsLong()` throws a raw `NumberFormatException`, `IllegalStateException` or `UnsupportedOperationException`. That breaks the contract that [malformed answers become IOExceptions](https://github.com/SonarSource/sonar-java/pull/6568#discussion_r4694569297). It also means a measure that only feeds a log line aborts the whole analysis: `open()` wraps the exception as "The SemSitter server could not start". The fix is to parse the optional measures leniently and return null when a value is not a number, or to wrap the failure as an `IOException` the way `exchange` does.

   Fix (Treat a measure that is not a number as unreported, so a diagnostic-only field cannot fail the analysis.):
   @Nullable
   private static Long longOrNull(JsonObject header, String name) {
     JsonElement value = header.get(name);
     if (value == null || !value.isJsonPrimitive() || !value.getAsJsonPrimitive().isNumber()) {
       return null;
     }
     return value.getAsLong();
   }

Verification Rules 3/3 met Knowledge 🔎 1 Repos 4 inspected · PRs 2 inspected

Functional validation No results

Rules 3 passed 2 not applicable

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

Knowledge 🔎 1 informed a finding

🔎 Malformed SemSitter answers are wrapped as IOExceptions informed a finding, open -> Malformed optional full-gen measure escapes as raw RuntimeException

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

SonarSource/sonarlint-language-server Inspected
SonarSource/sonar-iac Inspected
SonarSource/sonar-java-symbolic-execution Inspected
SonarSource/sonarlint-intellij Inspected

Cross-PR 2 PRs inspected 0 open impacts

PR 6568: JAVA-7394 Add the SemSitter frontend module and its protocol client 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.

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

Comment on lines +116 to 125
JsonObject header = send(request);
return new FullGenStats(header.get("files").getAsInt(), longOrNull(header, "elapsed_ms"), longOrNull(header, "failures"),
longOrNull(header, "peak_rss_kb"));
}

@Nullable
private static Long longOrNull(JsonObject header, String name) {
JsonElement value = header.get(name);
return value == null || value.isJsonNull() ? null : value.getAsLong();
}

@gitar-bot gitar-bot Bot Dec 2, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: Malformed optional full-gen measure escapes as raw RuntimeException

longOrNull runs in fullGen after send(...) has returned, so it is outside the try in exchange() that turns runtime parse failures into IOException("SemSitter server sent a malformed answer: ..."). If the server sends a value that is not a number for elapsed_ms, failures or peak_rss_kb (for example a string like "abc", an object or an array), getAsLong() throws a raw NumberFormatException, IllegalStateException or UnsupportedOperationException. That breaks the contract that malformed answers become IOExceptions. It also means a measure that only feeds a log line aborts the whole analysis: open() wraps the exception as "The SemSitter server could not start". The fix is to parse the optional measures leniently and return null when a value is not a number, or to wrap the failure as an IOException the way exchange does.

Treat a measure that is not a number as unreported, so a diagnostic-only field cannot fail the analysis.:

@Nullable
private static Long longOrNull(JsonObject header, String name) {
  JsonElement value = header.get(name);
  if (value == null || !value.isJsonPrimitive() || !value.getAsJsonPrimitive().isNumber()) {
    return null;
  }
  return value.getAsLong();
}

Was this helpful? React with 👍 / 👎

@sonarqube-next

sonarqube-next Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@rombirli
rombirli force-pushed the rombirli/semsitter-pvf branch 10 times, most recently from 74dcfab to 334ede0 Compare December 2, 2026 17:39
@leo-geoffroy-sonarsource
leo-geoffroy-sonarsource deleted the lge/semsitter-pvf-udg-timing branch December 4, 2026 10:28
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