A test class has two setup or teardown methods of the same kind, which run in no fixed order

tx0/java:duplicate-lifecycle-methodrecommendedwarningbug

What it finds

JUnit runs all methods annotated @BeforeEach, or @Before in JUnit 4, but in an order it does not define. With two of them, a setup that depends on the other works or fails depending on the JVM and the method names.

Reported is the second method of a class with the same one of @BeforeEach, @AfterEach, @BeforeAll, @AfterAll, @Before, @After, @BeforeClass and @AfterClass.

From the rule's source, duplicate_lifecycle_method.rs.

Example from the rule's tests
import org.junit.jupiter.api.BeforeEach; class SetupTest {  @BeforeEach  void first() {}   @BeforeEachtx0 reports: a second @BeforeEach method  void second() {}}
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:duplicate-lifecycle-method" = "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:duplicate-lifecycle-method] reason="..."

tx0 explain tx0/java:duplicate-lifecycle-method shows the same in the terminal. Found a false positive? Report it.