Skip to content

[java] SimplifyBooleanReturns - wrong suggested solution #4763

@adangel

Description

@adangel

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};`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions