A number is compared with itself to test for NaN

tx0/java:nan-checkstrictwarningstyle

What it finds

x != x is true only when x is NaN, which is a correct but cryptic way to say Double.isNaN(x); readers take it for a mistake.

Only operands whose declared type is the primitive double or float are reported; for the boxes, == compares references. The fix calls Double.isNaN or Float.isNaN, which gives the same result.

From the rule's source, nan_check.rs.

Example from the rule's tests
class Numbers {  boolean invalid(double d, float f, Double boxed, int i) {    boolean r = d != d;tx0 reports: d != d tests whether d is NaN    r = f == f;tx0 reports: f == f tests that f is not NaN    r = boxed != boxed;    r = i != i;    return r;  }}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:nan-check" = "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:nan-check] reason="..."

tx0 explain tx0/java:nan-check shows the same in the terminal. Found a false positive? Report it.