Skip to content

[java] SimplifyBooleanReturns should consider literal expression #3852

@ghost

Description

Affects PMD Version:6.42.0

Rule:SimplifyBooleanReturns

Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_java_design.html#simplifybooleanreturns

Description:
Hi, I found a false negative about the rule SimplifyBooleanReturns. Please read the following code example. PMD should have reported a warning at line 3, but it doesn't. However, I think this if-else statement can be simplified. Hence, I think this is a false negative.

Code Sample demonstrating the issue:

public boolean foo() {
    if (true) {  // should report a warning in this if-else statement
        return (true || false);  
    } else {
        return false;
    }
}

Expected outcome:A warning

PMD should report a violation at line 2, but doesn't. This is a false-negative.

Running PMD through: [Maven]

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions