wait() is called without a loop that checks the condition again
What it finds
lock.wait() can return without a notify, a spurious wakeup, and another thread may have changed the condition again between the notify and the moment this thread runs. Code that waits checks its condition in a loop: while (!ready) lock.wait();.
Reported are calls of wait with up to two arguments that are not inside a loop in the same method or lambda.
From the rule's source, wait_outside_loop.rs.
class Queue { private boolean ready; synchronized void await() throws InterruptedException { if (!ready) { wait();tx0 reports: wait() is not in a loop } while (!ready) { wait(100); } }} 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:wait-outside-loop" = "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:wait-outside-loop] reason="..."tx0 explain tx0/java:wait-outside-loop shows the same in the terminal. Found a false positive? Report it.