Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

JD.LOCK.WAIT

JD.LOCK.WAIT occurs when an Object.wait() method is called while the method is holding two or more locks. This checker checks only local locks.

Vulnerability and risk

Waiting on a monitor while two locks are held may cause deadlock. Performing a wait releases the lock only on the object being waited on, not on any other locks. Not necessarily a problem.

Mitigation and prevention

Preferably, call wait() method without lock held, or with a lock on the same object for which the wait is called.

Example 1

9      String name;
10     synchronized void waitForCondition(Object lock) {
11         try {
12             synchronized(lock) {
13                 name = "aa";
14                 lock.wait();
15             }
16         } catch (InterruptedException e) {
17             return;
18         }
19     }

JD.LOCK.WAIT is reported for line 14: Calling 'java.lang.Object.wait()' with two or more locks held '[lock, this]' could cause a deadlock.

Related checkers