| Severity | 3 |
|---|---|
| Enabled | yes |
| Waivable | |
| Violation |
public synchronized int get() {
while (available) {
try {
// wait for Producer to put value
wait();
} catch (InterruptedException e) {
logger.warn(e);
}
}
available = false;
// notify Producer that value has been retrieved
notify();
return contents;
}
public synchronized void put(final int value) {
while (available) {
try {
// wait for Consumer to get value
wait();
} catch (InterruptedException e) {
logger.warn(e);
}
}
contents = value;
available = true;
// notify Consumer that value has been set
notify();
}
|
| Fix |
public synchronized int get() {
while (available) {
try {
// wait for Producer to put value
wait();
} catch (InterruptedException e) {
logger.warn(e);
}
}
available = false;
// notify Producer that value has been retrieved
notifyAll();
return contents;
}
public synchronized void put(final int value) {
while (available) {
try {
// wait for Consumer to get value
wait();
} catch (InterruptedException e) {
logger.warn(e);
}
}
contents = value;
available = true;
// notify Consumer that value has been set
notifyAll();
}
|