Skip to content

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

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

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

Conversation

@Luqmansonar

Copy link
Copy Markdown
Contributor

Fixes two false-positive cases from SONARJAVA-6383:

  • Concatenation with a ternary whose branches are all non-dynamic (e.g. "... " + (asc ? "ASC" : "DESC")) is no longer reported.
  • Primitive and primitive-wrapper operands (e.g. " OFFSET " + offset) are no longer reported, consistent with the existing String.format handling.

Not addressed: s + "" (needs symbolic execution per the ticket).

Behavior change: SQLInjection.java line 190 (int id + " > query_id ") is now compliant instead of noncompliant. Ruling expectations may change; CI will propose updates.

🤖 Generated with Claude Code

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

hashicorp-vault-sonar-prod Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

SONARJAVA-6383

@gitar-bot

gitar-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · The SQL injection rule now treats primitive operands and constant ternaries as safe, so misclassification could suppress warnings for injectable query construction.

Reduces S2077 false positives in SQL string concatenation by skipping ternaries whose branches are all non-dynamic and primitive or primitive-wrapper operands like " OFFSET " + offset, consistent with existing String.format handling. 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-intellij Inspected
SonarSource/sonarlint-vscode Inspected
SonarSource/sonarlint-language-server Inspected
SonarSource/sonar-java-symbolic-execution Inspected
SonarSource/sonarqube 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

@Luqmansonar Luqmansonar added the False Positive Fix a rule raising False Positive label Oct 22, 2026
@sonarqube-next

Copy link
Copy Markdown
Contributor

@asya-vorobeva
asya-vorobeva self-requested a review October 22, 2026 09:22

@asya-vorobeva asya-vorobeva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Please take a look at my recent PR #6379 which does almost the same checks for another rule. I think it makes sense to wait for my PR to be merged and after it extract / reuse common functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

False Positive Fix a rule raising False Positive

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants