A value is compared with null right before an instanceof test that covers it

tx0/java:instanceof-covers-nullrecommendedwarningstyle

What it finds

value != null && value instanceof Name checks for null twice: instanceof is false for null already. The fix removes the first check.

From the rule's source, null_check_before_instanceof.rs.

Example from the rule's tests
class Checks {  boolean check(Object value, boolean ready) {    boolean a = value != null && value instanceof String;tx0 reports: value != null is implied by the instanceof test after it    boolean b = ready && value != null && value instanceof Integer;tx0 reports: value != null is implied    boolean c = value != null && ready;    return a || b || c;  }}
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 from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:instanceof-covers-null" = "warning"

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:instanceof-covers-null] reason="..."

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