Affects PMD Version:
6.25.0
Rule:
UselessParentheses
Description:
String Concatenation can trigger useless-parenthesis warning inappropriately under the right circumstances. Code sample is below (it's meaningless code just to demonstrate the issue). PMD detects UselessParenthesis on the "alpha+bravo" piece. Interestingly, the false-positive goes away if (any of): a) remove the 'charlie' check (apparently you need the OR-operation) or b) make it [equals("ConstantString")] (apparently, has to be comparing to a variable string).
The easy work-around is to invert the equals
Code Sample demonstrating the issue:
public static boolean isTest( final String alpha, final String bravo) { return "Charlie".equals(alpha) || (alpha + bravo).equals(alpha); }
Expected outcome:
False-positive: PMD reports UselessParenthesis, but they cannot be removed
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Detected via Maven as well as Eclipse plugin
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