Skip to content

[java] New rule: SuspiciousEqualsCall #6715

@UncleOwen

Description

@UncleOwen

Proposed Rule Name: SuspiciousEqualsCall? EqualsOnIncompatibleTypes?

Proposed Category: Error Prone

Description: This rule would trigger on calls of a.equals(b), where the static types of a and b don't have a common supertype (except Object).

Code like this usually comes up when you

  • were thinking of slightly different objects (e.g. you meant to call a.getId().equals(b) or something like that
  • messed up a refactoring.

Code Sample:

Integer i;
String s;
if (i.equals(s)) {    // violation
  // do stuff
}

Possible Properties:

  • Maybe a stricter mode, where one of the types must be a supertype of the other?

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:new-ruleProposal to add a new built-in rule

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions