Skip to content

SONARJAVA-7280 False negative java:S3626: a redundant return inside a lambda body is not reported - #6463

Merged
david-schroeter merged 5 commits into
masterfrom
ds/SONARJAVA-7280
Nov 4, 2026
Merged

david-schroeter merged 5 commits into
masterfrom
ds/SONARJAVA-7280

Conversation

@david-schroeter

@david-schroeter david-schroeter commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • Bug fix:
    • Extended RedundantJumpCheck to visit lambda expressions, so redundant returns in lambda bodies are reported
  • Tests:
    • Added regression cases covering nested lambdas, loops, conditional returns, and finally blocks
  • Messages:
    • Issue messages now name the jump, such as Remove this redundant continue.

This will update automatically on new commits.

@hashicorp-vault-sonar-prod

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

Copy link
Copy Markdown
Contributor

SONARJAVA-7280

@david-schroeter

Copy link
Copy Markdown
Contributor Author

/pvf

@hashicorp-vault-sonar-prod

Copy link
Copy Markdown
Contributor

📊 Performance Validation complete
🆕 12 new · 🗑️ 0 lost issues
View dashboard

Projects with unexpected PVF results:

  • crate

@rombirli rombirli 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.

LGTM, small suggestions

@rombirli rombirli 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.

🚀

@gitar-bot

gitar-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Extending S3626 to analyze lambda control-flow graphs changes Java diagnostics and could incorrectly flag non-redundant jumps as removable.

Extends RedundantJumpCheck to visit lambda expressions so redundant returns inside lambda bodies are reported, with regression tests covering nested lambdas, loops, conditional returns, and finally blocks. No issues found.

✅ 1 closed
Closed: Performance: CFG is built for every expression lambda, which can't hold a redundant jump

📄 java-checks/src/main/java/org/sonar/java/checks/RedundantJumpCheck.java:45-55
LambdaExpressionTree.body() is never null, so the body != null guard doesn't filter anything for lambdas. As a result, every lambda in the analyzed code goes through cfg(). For expression lambdas such as x -> x + 1 or () -> System.out.println(...), LambdaExpressionTreeImpl.cfg() runs CFG.buildCFG(singletonList(body)) (LambdaExpressionTreeImpl.java:100-104). An expression body can't contain a return or continue terminator, and any nested block lambda is visited on its own, so this CFG is built and then thrown away. Stream-heavy code has a lot of these lambdas. The fix is to analyze a lambda only when its body is a BLOCK. That also removes the second instanceof dispatch.

Verification Rules 1/1 met Repos 4 inspected · PRs 2 inspected

Functional validation No results

Rules 1 passed 2 not applicable

✅ Repository license compliance

Broader impact Repos 4 inspected PRs 2 inspected
Cross-repo 4 repositories inspected 0 open impacts

SonarSource/sonarqube Inspected
SonarSource/sonarlint-intellij Inspected
SonarSource/sonarlint-vscode Inspected
SonarSource/sonar-java-symbolic-execution Inspected

Cross-PR 2 PRs inspected 0 open impacts

PR 2033: SLI-3034 SLI-3035 analyzer updates Inspected
PR 1281: SLVSCODE-2040 SLVSCODE-2041 analyzer updates 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

@sonarqube-next

sonarqube-next Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@david-schroeter
david-schroeter merged commit 39553eb into master Nov 4, 2026
18 checks passed
@david-schroeter
david-schroeter deleted the ds/SONARJAVA-7280 branch November 4, 2026 08:26
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.

2 participants