SONARJAVA-6473 Fix FP in S3626: return inside try-finally in a loop#5701
SONARJAVA-6473 Fix FP in S3626: return inside try-finally in a loop#5701francois-mora-sonarsource wants to merge 5 commits into
Conversation
… loop A void return statement at the end of a try block shares the same CFG successor (the finally block) as the implicit fall-through path, causing the check to incorrectly report it as redundant. The fix suppresses the report when the finally block has a distinct continuation: a non-exit successor that is not a dead-loop condition (do-while/while with a constant-false condition). Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Code Review ✅ Approved 4 resolved / 4 findingsRestricts RedundantJumpCheck to prevent false positives when return statements appear inside try-finally loops. Resolved findings include incorrect loop continue handling, alphabetical import order, and improved dead-loop detection. ✅ 4 resolved✅ Edge Case: FP guard not applied to
|
| Auto-apply | Compact |
|
|
Was this helpful? React with 👍 / 👎 | Gitar
|




Summary
return;statements insidetryblocks as redundant when thetrywas wrapped in afinallyclause inside a loop. Both the return path and the fall-through path share the same CFG successor (thefinallyblock), causing the equality check to misidentify the jump as redundant.isFinallyBlockWithDistinctContinuation: before reporting, check whether the common successor is a finally block that leads somewhere genuinely different for the return path vs. the fall-through path (i.e., it has a non-exit successor that is not a dead-loop condition block).do-while(false),while(false), and constant-false expressions likeBoolean.FALSEor!true) are correctly excluded — returns inside them are redundant.Related
Test plan
// Noncompliantand compliant cases)while/for/do-whileloops with early return in try-finally — no issue raised// Noncompliantcases:returnat end of method in try-finally,do-while(false),while(false),do-while(Boolean.FALSE),do-while(!true)— issue correctly raised🤖 Generated with Claude Code