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
[java] ConsecutiveLiteralAppends false positive #1645
Conversation
ASTTryStatement added to BLOCK_PARENTS.
Generated by 🚫 Danger |
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.
@Shubham-2k17 thanks for the PR! This does cover the reported scenario, but I think we can improve it a little to cover some related use cases.
@@ -74,6 +75,7 @@ | |||
BLOCK_PARENTS.add(ASTIfStatement.class); | |||
BLOCK_PARENTS.add(ASTSwitchStatement.class); | |||
BLOCK_PARENTS.add(ASTMethodDeclaration.class); | |||
BLOCK_PARENTS.add(ASTTryStatement.class); |
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.
catch and finally should be added too. A simple test-case having 2 catch blocks do different appends / a catch + finally doing appends would trigger these FP too.
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.
I'm thinking, we actually may have similar FPs with lambdas, and we should add ASTLambdaExpression.class
here…
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.
I tried to check lambdas. No FPs.
I don't know the PMD codebase so I don't know what exactly this PR will change, but I would guess, it would just ignore literals, that are appended inside a try/catch block? So this won't trigger the rule while it should: final StringBuilder sb = new StringBuilder();
sb.append("foo");
try {
sb.append("bar");
final String res = methodThatMightThrow();
sb.append(res);
} catch (IOException ioe) {
...
} This is only a false positive, if the literal is appended inside the try/catch block, after a throwing method was called. I don't know if this case is covered by the PR. |
Hi @vbrandl, |
Hi @jsotuyod , |
@Shubham-2k17 @vbrandl interesting! I think you are actually right. I'm updating, adding that test case along with the lambda ones (which works as already stated), and merging. |
PR Description:
ASTTryStatement added to BLOCK_PARENTS.
fixes #1632