An IllegalMonitorStateException is caught, which only signals a missing synchronized block

tx0/java:caught-monitor-staterecommendedwarningbug

What it finds

IllegalMonitorStateException is thrown when wait or notify is called without holding the monitor: a programming error that synchronized fixes. Catching it hides the error and leaves the waiting thread without its notification.

Reported is a catch of IllegalMonitorStateException.

From the rule's source, caught_monitor_state.rs.

Example from the rule's tests
class Waiter {  void run(Object lock) {    try {      lock.notify();    } catch (IllegalMonitorStateException e) {tx0 reports: a synchronized block is missing      System.out.println(e);    }  }}
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:caught-monitor-state" = "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:caught-monitor-state] reason="..."

tx0 explain tx0/java:caught-monitor-state shows the same in the terminal. Found a false positive? Report it.