equals is called with null
What it finds
x.equals(null) is false for every x that keeps the contract of equals, and throws when x is null itself, so it never tests what it seems to. x == null does.
Calls among the arguments of an assertion are left alone: tests check this very contract with them. Some frameworks break the contract on purpose, with a placeholder object that equals null, and test for it this way; so the rule is not in the default tier.
From the rule's source, equals_null.rs.
class Checks { boolean missing(Object value, String name) { if (value.equals(null)) {tx0 reports: equals(null) is always false return true; } assertFalse(name.equals(null)); return value == null || name.equals("null"); } static void assertFalse(boolean value) {}} 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:
[rules]
"tx0/java:equals-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:equals-null] reason="..."tx0 explain tx0/java:equals-null shows the same in the terminal. Found a false positive? Report it.