You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] SimplifyBooleanReturns triggers inconsistently depending on redundant parentheses in return expression #6694
SimplifyBooleanReturns is sensitive to purely syntactic parenthesization of the returned expression. Two semantically identical methods — one whose return expression is wrapped in a redundant outer pair of parentheses, the other not — are treated differently: the parenthesized form is flagged, the bare form is not. Since the rule targets the structural pattern if (c) return X; return false; (which should simplify to return c && X;), it should either flag both forms or neither. The discrepancy looks like the rule's AST matcher does not unwrap a ParenthesizedExpression node before checking the return-value shape, causing a false-negative on the unparenthesized form (or, equivalently, unstable behavior across trivially equivalent code).
Code Sample demonstrating the issue:
publicclassFactoryChecker {
// BEFORE — NOT flagged by SimplifyBooleanReturnspublicbooleanisFactoryMethodA(Stringqualifier, Stringname) {
if (qualifier != null) {
returntypeEndsWith(qualifier, "Factory")
|| nameEndsWith(name);
}
returnfalse;
}
// AFTER — flagged by SimplifyBooleanReturns (line of the `if`)publicbooleanisFactoryMethodB(Stringqualifier, Stringname) {
if (qualifier != null) {
return (typeEndsWith(qualifier, "Factory")
|| nameEndsWith(name));
}
returnfalse;
}
privatebooleantypeEndsWith(Stringq, Stringsuffix) { returnq != null && q.endsWith(suffix); }
privatebooleannameEndsWith(Stringn) { returnn != null && n.endsWith("Factory"); }
}
Expected outcome: Both methods (which are semantically identical) should receive the same verdict — either both are reported as simplifiable to return qualifier != null && (typeEndsWith(...) || nameEndsWith(...));, or neither is.
Actual outcome: Only isFactoryMethodB (with the redundant outer parentheses) is reported; isFactoryMethodA is silently accepted.
Activity
Added testcase provied in issue pmd#6694
[java] Fix #6694: Trigger SimplifyBooleanReturns when expressions req…