JD.LOCK.NOTIFY

JD.LOCK.NOTIFY occurs when the code calls notify() or notifyAll() while two locks are held.

Vulnerability and risk

The code calls notify() or notifyAll() while two locks are held. If this notification is intended to wake up a wait() that is holding the same locks, it may deadlock, since the wait will only give up one lock and the notify will be unable to get both locks, and thus the notify will not succeed. If there is also a warning about a two-lock wait, the probability of a problem is quite high.

Mitigation and prevention

Preferably call a notify() method without locks held.

Example 1

Copy
      synchronized void finish(Object o) {
         synchronized(o) {
             o.notify();
         }
     }

JD.LOCK.NOTIFY is reported for line 11: Calling 'java.lang.Object.notify()' with two or more locks held '[this, o]' could cause a deadlock.

Related checkers