Affects PMD Version: 7.0.0
Rule: https://pmd.github.io/latest/pmd_rules_java_design.html#simplifybooleanreturns
Description: SimplifyBooleanReturns suggests a code transformation that makes the code harder to read. This happens when transforming an if/else statement to single-return form requires introducing parentheses because of operator precedence. I think the rule should only report if the conversion would not require introducing parentheses.
Code Sample demonstrating the issue:
private boolean isFactoryMethod(ASTMethodCall expr) {
if (expr.getQualifier() != null) { // nopmd
return typeEndsWith(expr.getQualifier(), "Factory")
|| nameEndsWith(expr.getQualifier());
}
return false;
}
when converted this would be
private boolean isFactoryMethod(ASTMethodCall expr) {
return expr.getQualifier() != null && (typeEndsWith(expr.getQualifier(), "Factory")
|| nameEndsWith(expr.getQualifier()));
}
which is ugly. Using an if-else statement allows avoiding parentheses.
see https://github.com/pmd/pmd/runs/5209308795?check_suite_focus=true
Expected outcome: no violation. That's a false positive.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Affects PMD Version: 7.0.0
Rule: https://pmd.github.io/latest/pmd_rules_java_design.html#simplifybooleanreturns
Description: SimplifyBooleanReturns suggests a code transformation that makes the code harder to read. This happens when transforming an if/else statement to single-return form requires introducing parentheses because of operator precedence. I think the rule should only report if the conversion would not require introducing parentheses.
Code Sample demonstrating the issue:
when converted this would be
which is ugly. Using an if-else statement allows avoiding parentheses.
see https://github.com/pmd/pmd/runs/5209308795?check_suite_focus=true
Expected outcome: no violation. That's a false positive.
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]