Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking Java files for == Error's, not limited to Strings

Many of the standard source code checking tools (PMD, FindBugs, Checkstyles) all implement a "String Equality" rule, where the usage of == (or !=) when comparing strings can be detected and reported as an error.

I'm looking to write (or configure!) a similar rule that works on a set of other object types in my API.

//Want to detect things like:
Instance a = ...;
Instance b = ...;
if ( a == b ) //Error here, not using a.equals(b)

Looking at PMD & FindBugs there is no obvious (or easy) way to do this, has anyone come across something like this ?

Cheers, Ro

like image 804
Ro. Avatar asked Nov 30 '11 21:11

Ro.


1 Answers

Doesn't CompareObjectsWithEquals in PMD work for you?

like image 185
Gonzalo Garcia Lasurtegui Avatar answered Nov 15 '22 10:11

Gonzalo Garcia Lasurtegui