Kingdom: Code Quality
Poor code quality leads to unpredictable behavior. From a user's perspective that often manifests itself as poor usability. For an attacker it provides an opportunity to stress the system in unexpected ways.
Code Correctness: Call to notify()
Abstract
It is ambiguous which thread will wake up when
notify()
is called.Explanation
There is no way to specify which thread will be awakened by calls to
Example 1: In the following code,
In this case, the developer intends to wake up the thread that calls
notify()
.Example 1: In the following code,
notifyJob()
calls notify()
.
public synchronized notifyJob() {
flag = true;
notify();
}
...
public synchronized waitForSomething() {
while(!flag) {
try {
wait();
}
catch (InterruptedException e)
{
...
}
}
...
}
In this case, the developer intends to wake up the thread that calls
wait()
, but it is possible that notify()
will notify a different thread than the intended one.References
desc.structural.java.code_correctness_call_to_notify