Do Not Catch IllegalMonitorStateException
ID |
java.no_catch_illegal_monitor_state |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
reliability |
Rationale
IllegalMonitorStateException is thrown when wait(), notify(), or notifyAll() is called on an object without holding its monitor (i.e. outside a synchronized block on that object). This is always a programming error. Catching it masks the concurrency bug instead of fixing the synchronization.
// Bad — hides a synchronization bug
try {
obj.wait();
} catch (IllegalMonitorStateException e) {
// swallowed
}