
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
50 lines
924 B
Plaintext
50 lines
924 B
Plaintext
== Why is this an issue?
|
|
|
|
``++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.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
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();
|
|
}
|
|
...
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public boolean isSuitable(Integer param) {
|
|
...
|
|
doSomething();
|
|
...
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this useless "instanceof" operator; it will always return "true".
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|