Skip to content

JAVA-7373 Document intentionally empty visitor overrides in SQLInjectionCheck - #6545

Closed
sonarqube-next[bot] wants to merge 3 commits into
masterfrom
remediation/c88246ac-ea54-4b83-a60a-ca1bbcae91ac
Closed

sonarqube-next[bot] wants to merge 3 commits into
masterfrom
remediation/c88246ac-ea54-4b83-a60a-ca1bbcae91ac

Conversation

@sonarqube-next

Copy link
Copy Markdown
Contributor

This PR was automatically created by the Remediation Agent.

Added explanatory comments to the empty visitClass and visitLambdaExpression overrides clarifying that traversal deliberately does not descend into nested/anonymous classes or nested lambdas. This resolves two java:S1186 findings and makes the intent of the no-op methods clear to future maintainers.

View Project in SonarQube


Fixed Issues

java:S1186 - Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation. • CRITICAL • View issue 1
java:S1186 - Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation. • CRITICAL • View issue 2

Location: java:java-checks/src/main/java/org/sonar/java/checks/SQLInjectionCheck.java:500

Why is this an issue?

An empty method is generally considered bad practice and can lead to confusion, readability, and maintenance issues. Empty methods bring no functionality and are misleading to others as they might think the method implementation fulfills a specific and identified requirement.

What changed

Added a comment inside the empty visitLambdaExpression override explaining that traversal intentionally does not descend into nested lambdas.

Added a comment inside the empty visitClass override explaining that traversal intentionally does not descend into nested/anonymous classes.

diff --git a/java-checks/src/main/java/org/sonar/java/checks/SQLInjectionCheck.java b/java-checks/src/main/java/org/sonar/java/checks/SQLInjectionCheck.java
index 6ce4867..c8fdbbd 100644
--- a/java-checks/src/main/java/org/sonar/java/checks/SQLInjectionCheck.java
+++ b/java-checks/src/main/java/org/sonar/java/checks/SQLInjectionCheck.java
@@ -498,10 +498,12 @@ public class SQLInjectionCheck extends IssuableSubscriptionVisitor {
 
     @Override
     public void visitLambdaExpression(LambdaExpressionTree lambdaExpressionTree) {
+      // do not descend into nested lambdas: their return statements belong to a different method
     }
 
     @Override
     public void visitClass(ClassTree tree) {
+      // do not descend into nested/anonymous classes: their return statements belong to a different method
     }
   }

SonarQube Remediation Agent uses AI. Check for mistakes.

Luqmansonar and others added 3 commits November 19, 2026 15:38
…ts reach the query

Do not report queries built from provably fixed content: nCopies and stream
joins of constants, same-class non-overridable helpers returning constants or
constant-only StringBuilders, and format/formatted over constants.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… a read-only builder usage

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@sonarqube-next
sonarqube-next Bot requested a review from Luqmansonar November 20, 2026 08:22
@gitar-bot

gitar-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🟢 Low risk

The two comments clarify intentional traversal boundaries; executable behavior and SQL-injection analysis remain unchanged, so the change has limited impact.

Adds explanatory comments to the empty visitLambdaExpression and visitClass overrides in SQLInjectionCheck.java, documenting that traversal intentionally does not descend into nested lambdas or nested/anonymous classes. No issues found.

Verification Rules 2/2 met PRs 2 inspected

Functional validation No results

Rules 2 passed 2 not applicable

✅ Internal artifact registries
✅ Repository license compliance

Broader impact PRs 2 inspected
Cross-PR 2 PRs inspected 0 open impacts

PR 6536: SONARJAVA-7025 S2077 should not raise when only fixed literal fragments reach the query Inspected
PR 6546: Document intentionally empty visitor overrides in SQLInjectionCheck 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

@hashicorp-vault-sonar-prod hashicorp-vault-sonar-prod Bot changed the title Document intentionally empty visitor overrides in SQLInjectionCheck JAVA-7373 Document intentionally empty visitor overrides in SQLInjectionCheck Nov 20, 2026
@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

JAVA-7373

@sonarqube-next

Copy link
Copy Markdown
Contributor Author

Base automatically changed from sonarjava-7025-s2077-fixed-fragments to master November 20, 2026 12:18
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