An assertion compares a string with a number or truth value, which are never equal

tx0/java:assertion-type-mismatchdefaulterrorbug

What it finds

assertEquals("42", count) fails whatever count holds: a String never equals an Integer, and the assertion compares them as objects. One side needs converting, or the expected value was written with the wrong type.

Reported is assertEquals, assertNotEquals or AssertJ's isEqualTo and isNotEqualTo that compare a value whose type this file shows to be String with one of a numeric, char or boolean type or box.

From the rule's source, assertion_type_mismatch.rs.

Example from the rule's tests
import static org.junit.jupiter.api.Assertions.assertEquals;import static org.assertj.core.api.Assertions.assertThat; class CountTest {  void check(int count, String name, Integer boxed) {    assertEquals("42", count);tx0 reports: never equal    assertThat(name).isEqualTo(5);tx0 reports: never equal    assertEquals("message", 42, count);    assertEquals(42, count);    assertEquals("a", name);    assertEquals(1, boxed);  }}
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:assertion-type-mismatch" = "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:assertion-type-mismatch] reason="..."

tx0 explain tx0/java:assertion-type-mismatch shows the same in the terminal. Found a false positive? Report it.