Skip to content

[java] EnumComparison: False positive for any object when object.equals(null) #6291

@ben-manes

Description

@ben-manes

Affects PMD Version: 7.19.0

Rule: EnumComparison
https://docs.pmd-code.org/pmd-doc-7.19.0/pmd_rules_java_bestpractices.html#enumcomparison

Description:

Code Sample demonstrating the issue:
Image

Image Image

This is reproducible as,

assertThat(new Object().equals(null)).isFalse();

Expected outcome:
Only enums should be reported on and null should not be assumed to be an enum.

Running PMD through: Gradle

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