A test uses random values, so a failure may not happen again when the test is run to investigate it
What it finds
A test that draws random input fails only for some values and passes on the next run. Fixed inputs, or a seeded generator whose seed is printed, make failures repeatable.
Reported is new Random() without a seed, Math.random(), UUID.randomUUID() and ThreadLocalRandom.current() inside a test method.
From the rule's source, random_test_data.rs.
import java.util.Random;import java.util.UUID; class RandomTest { @Test void run() { int a = new Random().nextInt();tx0 reports: hard to repeat String b = UUID.randomUUID().toString();tx0 reports: hard to repeat int c = new Random(42).nextInt(); }} 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:
[rules]
"tx0/java:random-test-data" = "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:random-test-data] reason="..."tx0 explain tx0/java:random-test-data shows the same in the terminal. Found a false positive? Report it.