SONARJAVA-5146 Fix S5411 IndexOutOfBoundsException for lambda parameter#5026
SONARJAVA-5146 Fix S5411 IndexOutOfBoundsException for lambda parameter#5026alban-auzeill merged 2 commits intomasterfrom
Conversation
| public static MethodInvocationTree parentMethodInvocationOfArgumentAtPos(@Nullable Tree argumentCandidate, int expectedArgumentPosition) { | ||
| if (argumentCandidate == null) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
You could chose to not accept the null argumentCandidate case to simplify this method. It looks like the caller won't give us a null tree anyway.
There was a problem hiding this comment.
In utility classes, it's easy to support and test null. I assume it will ease the test coverage work in the caller code, even if for the current rule we don't need it.
| public static VariableTree lamdaArgumentAt(@Nullable LambdaExpressionTree lambdaExpressionTree, int argumentPosition) { | ||
| if (lambdaExpressionTree == null) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
Same comment as for parentMethodInvocationOfArgumentAtPos
| ClassTree classTree = (ClassTree) compilationUnitTree.types().get(0); | ||
| List<Tree> members = classTree.members(); | ||
| LiteralTree literal1 = (LiteralTree) ((VariableTree) members.get(0)).initializer(); | ||
| MethodInvocationTree mathRound = (MethodInvocationTree) ((VariableTree) members.get(1)).initializer(); |
There was a problem hiding this comment.
should it be called mathMax instead for clarity?
There was a problem hiding this comment.
Oops, by bad, I changed the method and forgot to rename the variable.
|




SONARJAVA-5146