Skip to content
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

Merged
merged 2 commits into from
Feb 13, 2025

Conversation

alban-auzeill
Copy link
Member

@alban-auzeill alban-auzeill commented Feb 13, 2025

Comment on lines 68 to 71
public static MethodInvocationTree parentMethodInvocationOfArgumentAtPos(@Nullable Tree argumentCandidate, int expectedArgumentPosition) {
if (argumentCandidate == null) {
return null;
}
Copy link
Contributor

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.

Copy link
Member Author

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.

Comment on lines +85 to +88
public static VariableTree lamdaArgumentAt(@Nullable LambdaExpressionTree lambdaExpressionTree, int argumentPosition) {
if (lambdaExpressionTree == null) {
return null;
}
Copy link
Contributor

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();
Copy link
Contributor

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?

Copy link
Member Author

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.

@alban-auzeill alban-auzeill merged commit c771db2 into master Feb 13, 2025
14 of 15 checks passed
@alban-auzeill alban-auzeill deleted the alban/SONARJAVA-5146 branch February 13, 2025 17:05
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