Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] SimplifyBooleanReturns - wrong suggested solution #4763

Closed
adangel opened this issue Dec 7, 2023 · 1 comment · Fixed by #5373
Closed

[java] SimplifyBooleanReturns - wrong suggested solution #4763

adangel opened this issue Dec 7, 2023 · 1 comment · Fixed by #5373
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@adangel
Copy link
Member

adangel commented Dec 7, 2023

Affects PMD Version: 7.0.0-rc4

Rule: SimplifyBooleanReturns

Description:

I think, the suggested solution would result in wrong code.

Code Sample demonstrating the issue:

if (a == null) {
  return false;
}
return "FOO".equals(a.toString());

The suggestion is:

This if statement can be replaced by `return !{condition} || {elseBranch};`.

I think, this is wrong, it should be

This if statement can be replaced by `return !{condition} && {elseBranch};`.
@adangel adangel added the a:false-positive PMD flags a piece of code that is not problematic label Dec 7, 2023
@jsotuyod jsotuyod added needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale and removed needs:pmd7-revalidation The issue hasn't yet been retested vs PMD 7 and may be stale labels Mar 17, 2024
@rethab
Copy link

rethab commented Jul 31, 2024

With PMD 7.3.0, this is still wrong.

Code:

if (StringUtils.isAnyBlank(stringA, stringB)) {
    return false;
}
return Objects.equals(stringA, stringB);

PMD Error:

SimplifyBooleanReturns: This if statement can be replaced by `return !{condition} || {elseBranch};`

But as OP said, it should be && instead of ||.

@adangel adangel added this to the 7.8.0 milestone Nov 29, 2024
adangel added a commit that referenced this issue Nov 29, 2024
Merge pull request #5373 from oowekyala:issue4763-simplifyBooleanReturns-message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants