Affects PMD Version: 7.22.0
Rule:SimplifyBooleanReturns
Description:
The SimplifyBooleanReturns rule fails to trigger on the classic if-return boolean pattern when it is wrapped inside an unnecessary anonymous block {}.
This is a clear false negative — both patterns are semantically identical and can be safely replaced by a single return statement, yet only the direct case is flagged.
Code Sample demonstrating the issue:
public class a{
public boolean TP(Object o) {
if(obj == null) return false; // TP: correctly reported
return true;
}
public boolean FN(Object o) {
{
if(obj == null) return false; // FN: should report but doesn't
}
return true;
}
}
Expected outcome:
PMD should report SimplifyBooleanReturns for the if statement in both TP() and FN() with the message:
"This if statement can be replaced by return !{condition};"
But currently it only reports the direct case (TP), completely missing the extra block case (FN).
Running PMD through: CLI
Affects PMD Version: 7.22.0
Rule:SimplifyBooleanReturns
Description:
The SimplifyBooleanReturns rule fails to trigger on the classic
if-returnboolean pattern when it is wrapped inside an unnecessary anonymous block{}.This is a clear false negative — both patterns are semantically identical and can be safely replaced by a single
returnstatement, yet only the direct case is flagged.Code Sample demonstrating the issue:
Expected outcome:
PMD should report SimplifyBooleanReturns for the if statement in both
TP()andFN()with the message:"This if statement can be replaced by return
!{condition};"But currently it only reports the direct case (TP), completely missing the extra block case (FN).
Running PMD through: CLI