-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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] WhileLoopWithLiteralBoolean - false negative with complex expressions still occurs in PMD 6.52.0 #4250
Comments
Hi @Han-Cui , thanks for the report. However, I can't reproduce it: PMD 6.52.0 detects both cases correctly:
results in the following report:
Note that the beginning of the whole loop is marked, that is line 3 and 7, not as your comment indicates, where the loop condition is. Did you maybe override the rule instead of referencing it when you included it in your ruleset? Which ruleset are you using? |
Oh! Sorry for my carelessness, I made a stupid mistake. A few months ago I set PMD 6.42.0 in the environment for the sake of convenience and I forgot it... Indeed PMD 6.48.0 and the latest version report these cases correctly. Thanks for your prompt and kind reply very much! Additionally, should PMD consider more complex expressions like this? The following cases do not get report by PMD, public class Foo {
public void func() {
do {
// Loop Body
} while (false || false || false || false); // This is a false negative
do {
// Loop Body
} while (false | false | false | false | false); // This is a similar false negative.
}
} while the following cases are both reported correctly. public class Foo {
public void func() {
do { //reported: WhileLoopWithLiteralBoolean: The loop can be simplified.
// Loop Body
} while (false && false && false && false);
do { //reported: WhileLoopWithLiteralBoolean: The loop can be simplified.
// Loop Body
} while (false & false & false & false & false);
}
} |
I could improve the rule to consider also these cases with multiple repeating boolean literals, see #4264. However, I'm wondering: Did you see this code for real? Or did you just make it up? I can't imagine, that someone would write "false || false || false" in the first place, let alone that someone adds "|| false" to the end of such an expression... |
I don't think the problem is with WhileLoopWithLiteralBoolean. The expression |
Affects PMD Version: 6.48.0
Rule: WhileLoopWithLiteralBoolean
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#whileloopwithliteralboolean
Description:
This is an old issue from #3455
When I use pmd 6.48.0 and 6.52.0, I still met this False Negative.
Code Sample demonstrating the issue:
Expected outcome:
PMD should report a violation at line 4 and 5, but doesn't. This is a false-negative.
Running PMD through: [CLI]
The text was updated successfully, but these errors were encountered: