SONARJAVA-6673 S1602: Fix false positives - #6113
Conversation
…oads, MethodHandle signature-polymorphic invocations, and multiline lambda bodies Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Ruling Diff SummaryDetected changes in 2 rule files: 2 issues removed, 0 issues added. S1602 (
|
…er lambdas and update rule description Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Code Review ✅ Approved 4 resolved / 4 findingsFixes false positives in S1602 for Spring JDBC query overloads, MethodHandle signature-polymorphic invocations, and multiline lambda bodies. Multiline-body exemption contradicts the rule description and should be reconsidered, Spring JDBC exemption is broader than necessary for the ambiguity it addresses, and test coverage was reduced with removal of nested blocks and an untested return branch. ✅ 4 resolved✅ Bug: Multiline-body exemption contradicts the S1602 description
✅ Bug: Spring JDBC exemption is broader than the ambiguity it fixes
✅ Quality: Test coverage lost: nested blocks removed, return branch untested
✅ Bug: Without-semantic sample misses two expected issues (test fails)
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
lijun-chen-sonarsource
left a comment
There was a problem hiding this comment.
LGTM!
Just suggested some cosmetic change to the code to use the pattern matching syntax. Feel free to ignore.
| return parent != null && parent.is(Tree.Kind.METHOD_INVOCATION) | ||
| && SPRING_JDBC_QUERY_MATCHER.matches((MethodInvocationTree) parent); |
There was a problem hiding this comment.
| return parent != null && parent.is(Tree.Kind.METHOD_INVOCATION) | |
| && SPRING_JDBC_QUERY_MATCHER.matches((MethodInvocationTree) parent); | |
| return parent instanceof MethodInvocationTree methodInvocation | |
| && SPRING_JDBC_QUERY_MATCHER.matches(methodInvocation); |
| StatementTree statement = ((BlockTree) lambda.body()).body().get(0); | ||
| ExpressionTree expression = null; | ||
| if (statement.is(Tree.Kind.EXPRESSION_STATEMENT)) { | ||
| expression = ((ExpressionStatementTree) statement).expression(); | ||
| } else if (statement.is(Tree.Kind.RETURN_STATEMENT)) { | ||
| expression = ((ReturnStatementTree) statement).expression(); | ||
| } | ||
| return expression != null && expression.is(Tree.Kind.METHOD_INVOCATION) | ||
| && METHOD_HANDLE_INVOKE_MATCHER.matches((MethodInvocationTree) expression); |
There was a problem hiding this comment.
| StatementTree statement = ((BlockTree) lambda.body()).body().get(0); | |
| ExpressionTree expression = null; | |
| if (statement.is(Tree.Kind.EXPRESSION_STATEMENT)) { | |
| expression = ((ExpressionStatementTree) statement).expression(); | |
| } else if (statement.is(Tree.Kind.RETURN_STATEMENT)) { | |
| expression = ((ReturnStatementTree) statement).expression(); | |
| } | |
| return expression != null && expression.is(Tree.Kind.METHOD_INVOCATION) | |
| && METHOD_HANDLE_INVOKE_MATCHER.matches((MethodInvocationTree) expression); | |
| if (!(lambda.body() instanceof BlockTree block) || block.body().size() != 1) { | |
| return false; | |
| } | |
| StatementTree statement = block.body().get(0); | |
| ExpressionTree expression = null; | |
| if (statement instanceof ExpressionStatementTree expressionStatement) { | |
| expression = expressionStatement.expression(); | |
| } else if (statement instanceof ReturnStatementTree returnStatement) { | |
| expression = returnStatement.expression(); | |
| } | |
| return expression instanceof MethodInvocationTree methodInvocation | |
| && METHOD_HANDLE_INVOKE_MATCHER.matches(methodInvocation); |




Stop raising issues for Spring JDBC query overloads, MethodHandle signature-polymorphic invocations, and multiline lambda bodies