2023-05-03 11:06:20 +02:00
== Why is this an issue?
2021-06-08 14:23:48 +02:00
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.
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-06-08 14:23:48 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-06-08 14:23:48 +02:00
----
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[]
2021-06-08 15:52:13 +02:00
'''
2021-06-08 14:23:48 +02:00
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]