Object.equals(Object) check against class heirarchy
A source code analyzer
Brought to you by:
adangel,
juansotuyo
I would like to be able to identify when an Object.equals() check is likely to be nonsense.
For example:
if ("someStaticString".equals(someObject.getWhatever())
{
}
If the type returned by "someObject.getWhatever()" is not an 'instanceof' String, then this equality check is likely to be wrong. Technically one could override equals to do something funky to violate this premise, but if you're not, then this is an ugly bug.
Also, one could if desired extend this to the other relational operations in Java, such as Comparable.compareTo(Object), Comparator.compare(Object, Object), and any others I've overlooked.