Skip to content

SONARJAVA-6383 Fix FP on S2077 when using conditional operators or integer constants - #6406

Open
Luqmansonar wants to merge 1 commit into
masterfrom
luqman/fix-s2077-fp-ternary-primitives
Open

Luqmansonar wants to merge 1 commit into
masterfrom
luqman/fix-s2077-fp-ternary-primitives

Conversation

@Luqmansonar

Copy link
Copy Markdown
Contributor

Fixes two false positives from SONARJAVA-6383: constant ternaries and primitive operands. Not addressed: s + "" (needs symbolic execution). Replaces #6388, rebased on master after #6379.

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

Copy link
Copy Markdown
Contributor

SONARJAVA-6383

@Luqmansonar

Copy link
Copy Markdown
Contributor Author

Thanks @asya-vorobeva, this replaces #6388 and is rebased on master after #6379 merged. I checked #6379 for code to reuse. It only adds private methods that count '?' placeholders, so there is no shared helper to extract. The ternary logic differs: you take the max of the branches, S2077 flags the query if either branch is dynamic. The primitive check is one line (isPrimitive || isPrimitiveWrapper), and char is handled differently: you allow for '?', S2077 keeps its existing behavior. A shared helper would need flags for these differences, so I kept the code local.

@sonarqube-next

Copy link
Copy Markdown
Contributor

@gitar-bot

gitar-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Adjusting SQL injection analysis to treat primitive values and constant ternary branches as safe could suppress findings if these cases are misclassified.

Fixes two S2077 false positives in the Java analyzer: constant ternary expressions and primitive operands are no longer flagged. No issues found.

Verification Rules 2/2 met Repos 5 inspected

Functional validation No results

Rules 2 passed 1 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Broader impact Repos 5 inspected
Cross-repo 5 repositories inspected 0 open impacts

SonarSource/sonarlint-vscode Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarlint-language-server Inspected
SonarSource/sonar-java-symbolic-execution Inspected
SonarSource/sonar-lits 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