instanceof
operators that always return true
or false
are either useless or the result of a misunderstanding
which could lead to unexpected behavior in production.
public boolean isSuitable(Integer param) { ... String name = null; if (name instanceof String) { // Noncompliant; always false since name is null //... } if(param instanceof Number) { // Noncompliant; always true unless param is null, because param is an Integer doSomething(); } ... }
public boolean isSuitable(Integer param) { ... doSomething(); ... }
This rule is deprecated; use {rule:squid:S2589} instead.