Find locks that are not released on all paths

Proprietary

Marks lock(), and tryLock() whose result is discarded, on a local variable or parameter of type java.util.concurrent.locks.Lock when some path returns from the method without calling unlock() on it, which leaves the lock held for the caller to deal with. Paths that leave on an exception are not considered, so lock(); ..; unlock(); without a try/finally is not marked. Also not marked: locks held in fields or obtained from a call such as readWriteLock.readLock(), lockInterruptibly(), tryLock() whose result is read, the variable of a for-each loop, lock variables that are reassigned, aliased, passed on, compared, tested in a condition such as if (lock.isHeldByCurrentThread()), or captured by a lambda or nested class, acquires inside a lambda, locks whose unlock() or an early exit sits under an if whose condition reads a variable that also guards the acquire or a boolean or non-primitive variable the method reassigns, and methods that contain a switch, a labelled statement or an unlock() on anything other than a local variable or parameter.

io.moderne.staticanalysis.FindLockNotReleasedOnAllPaths
mod run . --recipe=io.moderne.staticanalysis.FindLockNotReleasedOnAllPaths

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.