rspec/rules/S2199/java/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
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.
2023-05-25 14:18:12 +02:00

51 lines
1.3 KiB
Plaintext

== Why is this an issue?
Once a value is known to be ``++null++`` or non-``++null++``, there's no reason to re-check it unless it has been changed (or potentially changed) in the interim. Doing so anyway may may just be an over-abundance of caution, but it could indicate a bug.
=== Noncompliant code example
[source,java]
----
public void assignCoach(Team team, Person person) {
if (team.hasCoach()) { // team is dereferenced
return;
}
if (team != null) { // Noncompliant; if we got this far, team is not null
//...
}
if (person != null) {
// ...
if (disqualified) {
person = getAlternate();
}
}
if (person != null) { // Compliant; person may have changed since last check
team.setCoach(person);
}
if (person != null) { // Noncompliant; no changes to person since last check
// ...
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== on 24 Oct 2014, 19:14:41 Ann Campbell wrote:
\[~nicolas.peru] note that I've marked this as covering:
* RCN_REDUNDANT_COMPARISON_OF_NULL_AND_NONNULL_VALUE
* RCN_REDUNDANT_COMPARISON_TWO_NULL_VALUES
My memory is fuzzy on exactly what code triggers these two & it's difficult to tell from the FB code. Please let me know if I got it wrong.
endif::env-github,rspecator-view[]