Why is this an issue?
The java.util.concurrent.locks.Condition
interface provides an alternative to the Object
monitor methods
(wait
, notify
and notifyAll
). Hence, the purpose of implementing said interface is to gain access to its more
nuanced await
methods.
Consequently, calling the method Object.wait
on a class implementing the Condition
interface is contradictory and should
be avoided. Use Condition.await
instead.
Code examples
Noncompliant code example
void doSomething(Condition condition) {
condition.wait(); // Noncompliant, Object.wait is called
...
}
Compliant solution
void doSomething(Condition condition) {
condition.await(); // Compliant, Condition.await is called
...
}
References