Affects PMD Version: 6.x
Rule: AvoidLiteralsInIfCondition
Description:
String literals are reported for deeper expressions when the property ignoreExpressions
is true (that's the default value).
Note: This is fixed already with PMD 7.0.0-rc1.
Found via #3123 .
Code Sample demonstrating the issue:
public class AvoidLiteralsInIfCondition { private static final int MY_CONSTANT = 1; public void test(int i, String s) { if ("test".equals(s)) {} // expected violation is missing (false negative) if (i == 1) {} // expected violation // the following literals should be ignored because ignoreExpression=true if (i == MY_CONSTANT && "test".equals(s)) {} // violation for "test" (false positive) if (i == 1 && "test".equals(s)) {} // violation for "test" (false positive) } }
Expected outcome:
PMD reports a violation at lines 8+9, but that's wrong. That's a false positive.
PMD doesn't report a violation at line 4, but that's wrong. That's a false negative.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4