SONARJAVA-6455 S7467: FP on broken semantics - #5853
Conversation
Without semantics, catch parameter usages() is always empty, causing false positives. Guard with context.getSemanticModel() != null. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code Review ✅ ApprovedGuards catch parameter usage checks with a semantic model null check to prevent false positives when semantics are absent. No issues found. 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 |
|
|
This PR is stale because it has been open 7 days with no activity. If there is no activity in the next 7 days it will be closed automatically |
francois-mora-sonarsource
left a comment
There was a problem hiding this comment.
Approving — the guard is correct for the case it targets (semantic model entirely absent), and the flipped verifyNoIssues() in test_without_semantics covers it.
One non-blocking note on test coverage. The added executor_run_compliant() sample doesn't exercise the change: it's analyzed with the full default classpath, so e resolves and has a usage, and it passes on the parent commit too. It also repeats the lambda-usage case already at line 117.
While checking that, I found a separate FP on partial semantics that this PR doesn't cover — usages() is also empty when the parameter binds fine but its usage sits in a lambda body ECJ couldn't bind. Reproduced against this branch:
void usedInsideLambdaWithUnresolvedFunctionalInterface() {
try {
Integer.parseInt("x");
} catch (NumberFormatException e) { // FP: "Replace e with an unnamed pattern"
Unknown.run(() -> System.out.println(e.getMessage()));
}
}NumberFormatException resolves, the semantic model is present, so the new guard passes — but the usage inside the lambda was never registered. Note this is not fixable by checking v.symbol().isUnknown() instead (I tried; the symbol is known here). It needs something like detecting unresolved constructs in the parameter's scope, so it's a design question rather than a condition tweak.
Worth a follow-up ticket rather than blocking this one. Happy to file it with the reproducer.
Absolutely agree, and I've added this test case only to illustrate customer's issue.
Yep, it's well-known problem for many rules. Good point, I'll create JIRA ticket to investigate and fix this point. |




Without semantics, catch parameter usages() is always empty, causing false positives. Guard with context.getSemanticModel() != null.