Repository navigation
SONARJAVA-7236 Experiment: let semsitter read sourcepath files that are not analyzed - #6501
leo-geoffroy-sonarsource wants to merge 4 commits into
Conversation
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>
…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>
| /// 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) | ||
| } |
There was a problem hiding this comment.
💡 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>
Code Review 👍 Approved with suggestions 🟡 Medium risk 0 closed / 1 findingsLoading 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 💡 Edge Case: spelled_descriptor drops array dimensions on type-variable markers📄 semsitter-bridge/src/types.rs:185-195
Erase the type-variable element but keep its array dimensions🤖 Prompt for agentsVerification Rules 2/2 met PRs 3 inspectedFunctional validation No results Rules 2 passed 2 not applicable
Broader impact PRs 3 inspectedCross-PR 3 PRs inspected 0 open impacts
Auto-approval Not enabledFor more verification details, 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 |
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
sonar.java.internal.sourcepath: comma-separated directories, relative to the module base directory or absolute.JParserConfig.openBridgesends the bridge the analyzed files plus every.javafile under those directories, deduplicated by real path. The bridge already accepts files in several folders and resolves types across everything it scans.parseFile, so the sourcepath files never reach the rules and never get issues.JavaFrontend) and the file-by-file path (JavaAstScanner). Without the property, nothing changes.Tests
JParserConfigTest:Example.javaresolvescom.a.Util#makefrom a sourcepath file and onlyExample.javais returned.SonarComponentsTest: property parsing and resolution against the base directory.Known limits of the base branch, not changed here:
JProblemTest,JWarningTest,JParserTest). I moved them aside to run the tests above.SonarComponentsTest$Loggingfail on SONARJAVA-7236 Experiment: supply only the JDK classpath to semsitter #6497 with or without this change.@Deprecatedand resolved through the bridge isn't flagged as deprecated by the translation, though the bridge reports the annotation. Cross-file rules such asjava:S1874miss it, with or without this change.🤖 Generated with Claude Code
Summary by Gitar
framework_typeinsemsitter-bridge/src/types.rsto answer library types from the framework API databaseudg-lang-javacrate tosemsitter-bridge/Cargo.tomlfor theJAVA_DBtableThis will update automatically on new commits.