Skip to content

[java] CompareObjectsWithEqualsRule: False positive with Enums #2716

@ghost

Description

Affects PMD Version:
6.26.0
Rule:
CompareObjectsWithEquals

Description:
With #885 this rule was fixed to not show a false-positive violation when comparing enums with '=='.
However there is still a way to get a false-positive.

Code Sample demonstrating the issue:

public class EnumTest {
	enum Type {
		A, B;
	}
	
	private final Type type = Type.A;
	
	public String isTypeA(Type param) {
		return param == type ? "Yes" : "No";
	}
}

Expected outcome:
No violation -> false-positive

Running PMD through: Eclipse

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions