apache / apache/druid

Catch wrong use of `==`/`!=` and `equals()`/`!equals()` in equals() implementations

Open
#8,330 0 comments 0 reactions 0 assignees View on GitHub
Area - Automation/Static Analysis Contributions Welcome
Dominant language
Java
Stars
14.1k
Forks
3.8k
Avg merge
2d 58m
Merged PRs (30d)
233

Description

Bugs like this: #8326 could be caught on the static analysis level, using Regex patterns ([Checkstyle Regexp](https://checkstyle.org/config_regexp.html)) or [Structural search inspection](https://github.com/apache/incubator-druid/blob/master/dev/teamcity.md#creating-a-custom-inspection-from-a-structural-search-pattern).

Example of regex which should have caught #8326: `(?m)return ([^\;]+)(this\.)?([a-zA-Z]+) \!\= [a-zA-Z]+\.\1`

Similar regexes could be created for `equals()`, `Object.equals()`, as well as incorrect use in
```java
if (x != that.x) {
return false;
}
```
code in `equals()` implementations.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the linked Checkstyle Regexp documentation, the structural-search inspection guidance in dev/teamcity.md, and the buggy example in issue #8326. Define the checks for ==/!= and equals()/!equals() inside equals() implementations, then verify that the resulting patterns catch the example without unacceptable false positives.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.