-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SONARJAVA-5146 Fix S5411 IndexOutOfBoundsException for lambda parameter #5026
Conversation
public static MethodInvocationTree parentMethodInvocationOfArgumentAtPos(@Nullable Tree argumentCandidate, int expectedArgumentPosition) { | ||
if (argumentCandidate == null) { | ||
return null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be called mathMax
instead for clarity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, by bad, I changed the method and forgot to rename the variable.
|
SONARJAVA-5146