Skip to content

SONARJAVA-7236 Experiment: let semsitter read sourcepath files that are not analyzed - #6501

Draft
leo-geoffroy-sonarsource wants to merge 4 commits into
experiment/semsitter-without-dependenciesfrom
experiment/semsitter-sourcepath
Draft

leo-geoffroy-sonarsource wants to merge 4 commits into
experiment/semsitter-without-dependenciesfrom
experiment/semsitter-sourcepath

Conversation

@leo-geoffroy-sonarsource

@leo-geoffroy-sonarsource leo-geoffroy-sonarsource commented Nov 11, 2026 •

Copy link
Copy Markdown

SONARJAVA-7236: Built on top of #6497 (JDK-only classpath). It lets semsitter see project files that are not analyzed, so a request of a few files can still resolve the project's own types.

A3S (SonarQube Vortex analysis) analyzes one or a few files per request. Without the rest of the project, semsitter only sees those files, so it misses the project's own classes as well as the libraries. A3S will restore the project sources next to the request and point this property at them.

What

  • New internal property sonar.java.internal.sourcepath: comma-separated directories, relative to the module base directory or absolute.
  • JParserConfig.openBridge sends the bridge the analyzed files plus every .java file under those directories, deduplicated by real path. The bridge already accepts files in several folders and resolves types across everything it scans.
  • Only the analyzed files go through parseFile, so the sourcepath files never reach the rules and never get issues.
  • Wired in both the batch path (JavaFrontend) and the file-by-file path (JavaAstScanner). Without the property, nothing changes.
  • No change to the bridge itself.

Tests

  • JParserConfigTest:
    • file selection: deduplication, nested directories, missing directories;
    • an end-to-end batch parse with the real bridge, where Example.java resolves com.a.Util#make from a sourcepath file and only Example.java is returned.
  • SonarComponentsTest: property parsing and resolution against the base directory.

Known limits of the base branch, not changed here:

🤖 Generated with Claude Code


Summary by Gitar

  • Bridge type lookup:
    • Added framework_type in semsitter-bridge/src/types.rs to answer library types from the framework API database
  • Dependency:
    • Added udg-lang-java crate to semsitter-bridge/Cargo.toml for the JAVA_DB table
  • Removed Java reader:
    • Dropped the Java-side framework database reader, so the bridge now answers these lookups instead

This will update automatically on new commits.

The new internal property sonar.java.internal.sourcepath lists directories
whose Java files are sent to the semsitter bridge next to the analyzed files.
The bridge resolves types across all of them, but only the analyzed files are
parsed and reach the rules. A3S uses it to give semsitter the rest of the
project when a request only contains a few files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hashicorp-vault-sonar-prod

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

Copy link
Copy Markdown
Contributor

SONARJAVA-7236

…rk database

The bridge `types` lookup now falls back to the framework API database
(JAVA_DB of udg-lang-java) after the project, the classpath and the JDK, so
library types such as org.junit.Assert resolve with their members and the
front end no longer builds unknown methods for them.

The front end can also complete the answer from database files given with
-Dsonar.java.semsitter.frameworkDb, and read extra library jars given with
-Dsonar.java.semsitter.extraClasspath (both experiment hooks, off by default).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The bridge `types` lookup now answers library types from the framework
database itself, so the front end no longer needs its own reader nor the
extra classpath experiment hook.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Comment on lines +185 to +195
/// The JVM descriptor of a type as the framework database spells it: `void`, a primitive, a binary name, each followed
/// by one `[]` per array dimension. A `$T` marker (a type variable) is its erasure, `Object`.
fn spelled_descriptor(spelled: &str) -> String {
if spelled == "void" {
return "V".to_string();
}
if spelled.is_empty() || spelled.starts_with('$') {
return "Ljava/lang/Object;".to_string();
}
field_descriptor(spelled)
}

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: spelled_descriptor drops array dimensions on type-variable markers

spelled_descriptor returns Ljava/lang/Object; for anything starting with $ before it looks for the [] suffixes. Its own doc comment says each spelling may be followed by one [] per array dimension. So a type-variable array such as $T[] (a T[] parameter, or T... written as an array) turns into Ljava/lang/Object; when it should be [Ljava/lang/Object;. The frontend then builds the member's parameter or return type from this descriptor (JSema.parameterTypesOf/readDescriptor), so the arity/type match for calls passing arrays fails and the call stays unresolved. Fix: strip the [] suffixes first and only map the bare $... element to Object.

Erase the type-variable element but keep its array dimensions:

fn spelled_descriptor(spelled: &str) -> String {
  if spelled == "void" {
    return "V".to_string();
  }
  let element = spelled.trim_end_matches("[]");
  if element.is_empty() || element.starts_with('$') {
    let dimensions = (spelled.len() - element.len()) / 2;
    return format!("{}Ljava/lang/Object;", "[".repeat(dimensions));
  }
  field_descriptor(spelled)
}
  • Apply fix

Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎

… the PoC

Pin semsitter to the PoC branch that adds 646 library types (JUnit, AssertJ,
Spring, Servlet, JPA, ...) to the framework database, and rebuild the five
prebuilt bridges with archive-bridge.sh. With the bridge answering `types`
from that database, library types resolve without any classpath.

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

gitar-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 🟡 Medium risk 0 closed / 1 findings

Loading configured sourcepath and framework API types into semantic resolution could alter bindings and produce different rule findings.

Adds a bridge-side framework type lookup in semsitter-bridge/src/types.rs and drops the Java-side framework database reader, so library type lookups are answered from the semsitter framework database. Approved with suggestions: spelled_descriptor maps type-variable arrays such as $T[] to Ljava/lang/Object; instead of [Ljava/lang/Object;, which can leave calls passing arrays unresolved. Strip the [] suffixes before mapping the bare $... element to Object.

💡 Edge Case: spelled_descriptor drops array dimensions on type-variable markers

📄 semsitter-bridge/src/types.rs:185-195

spelled_descriptor returns Ljava/lang/Object; for anything starting with $ before it looks for the [] suffixes. Its own doc comment says each spelling may be followed by one [] per array dimension. So a type-variable array such as $T[] (a T[] parameter, or T... written as an array) turns into Ljava/lang/Object; when it should be [Ljava/lang/Object;. The frontend then builds the member's parameter or return type from this descriptor (JSema.parameterTypesOf/readDescriptor), so the arity/type match for calls passing arrays fails and the call stays unresolved. Fix: strip the [] suffixes first and only map the bare $... element to Object.

Erase the type-variable element but keep its array dimensions
fn spelled_descriptor(spelled: &str) -> String {
  if spelled == "void" {
    return "V".to_string();
  }
  let element = spelled.trim_end_matches("[]");
  if element.is_empty() || element.starts_with('$') {
    let dimensions = (spelled.len() - element.len()) / 2;
    return format!("{}Ljava/lang/Object;", "[".repeat(dimensions));
  }
  field_descriptor(spelled)
}
🤖 Prompt for agents
Code Review: Adds a bridge-side framework type lookup in `semsitter-bridge/src/types.rs` and drops the Java-side framework database reader, so library type lookups are answered from the semsitter framework database. Approved with suggestions: `spelled_descriptor` maps type-variable arrays such as `$T[]` to `Ljava/lang/Object;` instead of `[Ljava/lang/Object;`, which can leave calls passing arrays unresolved. Strip the `[]` suffixes before mapping the bare `$...` element to `Object`.

1. 💡 Edge Case: spelled_descriptor drops array dimensions on type-variable markers
   Files: semsitter-bridge/src/types.rs:185-195

   `spelled_descriptor` returns `Ljava/lang/Object;` for anything starting with `$` before it looks for the `[]` suffixes. Its own doc comment says each spelling may be followed by one `[]` per array dimension. So a type-variable array such as `$T[]` (a `T[]` parameter, or `T...` written as an array) turns into `Ljava/lang/Object;` when it should be `[Ljava/lang/Object;`. The frontend then builds the member's parameter or return type from this descriptor (`JSema.parameterTypesOf`/`readDescriptor`), so the arity/type match for calls passing arrays fails and the call stays unresolved. Fix: strip the `[]` suffixes first and only map the bare `$...` element to `Object`.

   Fix (Erase the type-variable element but keep its array dimensions):
   fn spelled_descriptor(spelled: &str) -> String {
     if spelled == "void" {
       return "V".to_string();
     }
     let element = spelled.trim_end_matches("[]");
     if element.is_empty() || element.starts_with('$') {
       let dimensions = (spelled.len() - element.len()) / 2;
       return format!("{}Ljava/lang/Object;", "[".repeat(dimensions));
     }
     field_descriptor(spelled)
   }

Verification Rules 2/2 met PRs 3 inspected

Functional validation No results

Rules 2 passed 2 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Broader impact PRs 3 inspected
Cross-PR 3 PRs inspected 0 open impacts

PR 6497: SONARJAVA-7236 Experiment: supply only the JDK classpath to semsitter Inspected
PR 6503: Simplify the parser interface Inspected
PR 6308: SONARJAVA-7137 Optionally rely on source paths to resolve types during analyses 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

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