A variable is dereferenced right where a test has shown it to be null

tx0/java:dereference-of-nulldefaulterrorbug

What it finds

if (name == null) { log.warn("missing " + name.trim()); } throws a NullPointerException on the very path where name was found to be null. So do user == null && user.isAdmin() and user != null || user.isGuest(), where the right operand runs only when the left one found null. The test was likely meant the other way round, or the wrong variable is used.

Reported is a field access, method call or array access on a local variable or parameter where a test has just shown it to be null: in the branch of an if or a conditional expression that runs when x == null holds, alone or in a chain of &&, or when x != null fails, alone or in a chain of ||, and in the right operand of && and || alike. A branch that assigns the variable anywhere is left alone, and so is code inside lambdas and class bodies.

From the rule's source, dereference_of_null.rs.

Example from the rule's tests
class Names {  String show(String name, String other) {    if (name == null) {      return "missing " + name.trim();tx0 reports: name is null here    }    boolean a = other == null && other.isEmpty();tx0 reports: other is null here    boolean b = other != null || other.isBlank();tx0 reports: other is null here    if (other != null) {      return other.trim();    } else {      System.out.println(other.length());tx0 reports: other is null here    }    if (name == null) {      name = "";      return name.trim();    }    boolean c = name != null && name.isEmpty();    return a || b || c ? "" : name;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:dereference-of-null" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:dereference-of-null] reason="..."

tx0 explain tx0/java:dereference-of-null shows the same in the terminal. Found a false positive? Report it.