pmd / pmd/pmd

[java] New rule: SuspiciousEqualsCall

Open
#6,715 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

a:new-rule
Dominant language
Java
Stars
5.5k
Forks
1.6k
Avg merge
1d 19h
Merged PRs (30d)
54

Description

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) subtype.

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the a.equals(b) call pattern in the issue as the entry point and review existing Java rule implementations for type comparisons. No files or tests are named, so locate the rule and test conventions first. Done means the rule reliably identifies equals calls between incompatible static types, with the handling of Object and any stricter mode decided and covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.