Skip to content

[java] UnnecessaryLocalBeforeReturn false positive when negating variable #2206

@C-Otto

Description

@C-Otto

Rule Set: design

Code Sample demonstrating the issue:

public boolean isOk() {
    boolean isWrong = foo();
    return !isWrong;
}

I'd like to make the negation explicit, as the tiny character ! is easy to read over.

Violation:

[UnnecessaryLocalBeforeReturn] Consider simply returning the value vs storing it in local variable 'isWrong'

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