Repository navigation
Conversation
| public static final String EXECUTABLE_ENVIRONMENT = "SEMSITTER_ANALYZER"; | ||
| public static final String CLIENT_ID_ENVIRONMENT = "SONAR_JAVA_LAUNCHDARKLY_CLIENT_ID"; | ||
| static final boolean FLAG_DEFAULT = false; | ||
| static final boolean FLAG_DEFAULT = true; |
There was a problem hiding this comment.
💡 Quality: Failure log and Javadoc still say the default frontend is used
Now that FLAG_DEFAULT is true, isFlagOn returns true when LaunchDarkly can't be reached (line 90), so SemSitter is the frontend that runs. The warning on line 89 still says "the default frontend is used", which is the opposite of what happens. The class Javadoc (line 35) also still says "Anything that goes wrong while asking leaves the default frontend in use". Anyone reading the logs or the docs during a ruling or CI run will get the wrong idea about which parser handled the analysis. The test name without_property_nor_client_id_the_default_frontend_stays (test line 111) has the same problem, since with no client id the provider now turns SemSitter on. Fix: build the log message and Javadoc from FLAG_DEFAULT, or reword them to be neutral, and rename the test.
Make the warning match what actually happens, whatever the default value is:
LOG.warn("The SemSitter frontend flag could not be read, it defaults to {}: {}", FLAG_DEFAULT ? "on" : "off", e.getMessage());
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
This comment has been minimized.
This comment has been minimized.
088ea84 to
d79893d
Compare
d79893d to
6bba146
Compare
| if (name.endsWith(".*")) { | ||
| return declaredIn(symbol, qualifier.replace('$', '.'), importTree.isStatic()); | ||
| } |
There was a problem hiding this comment.
⚠️ Bug: Static on-demand import flagged unused when only inherited members used
With this PR the SemSitter frontend is on by default, so CompilerWarnings now produces the UNUSED_IMPORT warnings that S1128 reads. For a single static import, uses() calls isMemberOf, which also accepts members the imported type inherits. For a static on-demand import it calls declaredIn, which only accepts a member whose owner is exactly the imported type (line 717). Take import static org.mockito.Mockito.*; in a file that only calls any() or eq(). Those methods are declared in ArgumentMatchers, which Mockito extends, so the import gets a false 'never used' warning. ECJ does not report this. Fix: in the static, non-type branch of declaredIn, use the same inheritance-aware check as isMemberOf.
Reuse the inheritance-aware member check for static on-demand imports (make declaredIn an instance method).:
private boolean declaredIn(Symbol symbol, String qualifier, boolean isStatic) {
if (symbol.isUnknown()) {
return false;
}
if (isStatic) {
if (symbol.isTypeSymbol()) {
String type = dottedType(symbol);
return type.startsWith(qualifier + ".") && type.indexOf('.', qualifier.length() + 1) < 0;
}
return isMemberOf(symbol, qualifier);
}
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
| return symbol.owner() instanceof Symbol.TypeSymbol owner && dottedType(owner).equals(qualifier); | ||
| } | ||
| Symbol type = symbol; | ||
| if ("<init>".equals(symbol.name())) { | ||
| type = symbol.owner(); |
There was a problem hiding this comment.
💡 Bug: Type-import-on-demand counted as used by types from subpackages
For a non-static on-demand import, declaredIn treats the import as used whenever the type's dotted name starts with qualifier + "." (line 723). It never checks that the type sits directly in that package or type, while the static branch above it does (line 715). So import java.util.*; import java.util.concurrent.ConcurrentHashMap; with only new ConcurrentHashMap<>() in the body marks java.util.* as used: java.util.concurrent.ConcurrentHashMap starts with java.util.. The unused import is then never reported, and S1128 misses an issue ECJ would raise. Fix: also require that no further . follows the qualifier, as the static branch does.
Only count types declared directly in the imported package/type.:
String dotted = dottedType(type);
return type.isTypeSymbol() && !type.isUnknown() && dotted.startsWith(qualifier + ".") && dotted.indexOf('.', qualifier.length() + 1) < 0;
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
| @Override | ||
| public final boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (!(obj instanceof JSymbol other) || kind != other.kind) { | ||
| return false; | ||
| } | ||
| if (id != null && other.id != null) { | ||
| return id.equals(other.id); | ||
| } | ||
| return name.equals(other.name) && Objects.equals(owner, other.owner); | ||
| } | ||
|
|
||
| @Override |
There was a problem hiding this comment.
💡 Bug: JSymbol equals/hashCode contract violated for id-less symbols
When one of the two symbols has no id, JSymbol.equals compares them by name and owner (lines 141-144). hashCode still hashes id when it is present and name otherwise (line 150). Production code does create id-less symbols, for example the unresolved JMethodSymbol(sema, null, name) in SemSitterTranslator line 2241 and the sema's unknownSymbol. An id-less symbol can therefore equal a symbol whose id is set while having a different hash code. That breaks the Object.hashCode contract and gives inconsistent results in HashMap/HashSet lookups. Fix: base hashCode only on fields that equals always compares, such as kind and name.
Hash only on fields equals always agrees on.:
hash = Objects.hash(kind, name);
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
6bba146 to
b655d0a
Compare
|
/pvf |
|
📊 Performance Validation complete Projects with unexpected PVF results:
|
…ature flag The translator turns the SemSitter documents into the Java tree the checks run on. The flag keeps the default frontend until it turns on.
…as ECJ gives them
…xecutable is known The flag default flips to on, so an analysis with a SemSitter executable parses with SemSitter unless the flag or sonar.java.semsitter.enabled turns it off.
…uses that frontend The performance validation runners have no SemSitter executable. This build ships the protocol 2 Linux server and turns the frontend on when no path is configured.
…ing PVF Other Linux analyses, including ruling, stay on the default frontend.
439646f to
4db55e1
Compare
CI failed: The ruling-update job failed because its prerequisite ruling QA job was cancelled, so no artifacts were downloaded and the sync step errored. The analyzer could not tie the upstream cancellation to this PR, so the failure is attributed to neither the change nor a confirmed cause.OverviewThe ruling-update job failed because its prerequisite ruling QA job was cancelled, so no artifacts were downloaded and the sync step errored. The analyzer could not tie the upstream cancellation to this PR, so the failure is attributed to neither the change nor a confirmed cause. FailuresRuling-update job failed after upstream ruling QA was cancelled, leaving no artifacts to sync
Summary
Code Review
|
| Auto-apply | Compact | Unblock |
|
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|
/pvf |
|
|
📊 Performance Validation complete Projects with unexpected PVF results:
|




Stacked on #6547. Do not merge.
Flips the default of the
sonar-java-semsitter-frontendflag to on, so any analysis that knows a SemSitter executable (sonar.java.semsitter.executableorSEMSITTER_ANALYZER) parses with SemSitter.sonar.java.semsitter.enabled=falseor the flag set to off still brings back ECJ. Without an executable nothing changes.Used to exercise the SemSitter frontend end to end on CI and on ruling once the server binary is provided.
Summary by Gitar
FLAG_DEFAULTto true so SemSitter is used whenever an executable is knownBundledServerto use the Linux SemSitter server when no executable is configuredSemSitterTranslator::translateand reports syntax errors with line and columnrequireFilesSizemaxsize insonar-java-plugin/pom.xmlto 50000000 to fit the bundled serverAnnotationValueImplThis will update automatically on new commits.