eclipse-platform / eclipse-platform/eclipse.platform
InputStreamMonitor.writeNext() wait() not in loop — vulnerable to spurious wakeups
- Dominant language
- Java
- Stars
- 165
- Forks
- 174
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 22
Description
In `InputStreamMonitor.writeNext()`, the `fLock.wait()` call at line 189 is guarded by an `if` check:
```java
synchronized(fLock) {
// Queue could receive more input between last empty check and
// lock acquire. See https://bugs.eclipse.org/550834
if (fQueue.isEmpty()) {
fLock.wait();
}
}
```
Per the [Java specification](https://docs.oracle.com/javase/specs/jls/se17/html/jls-17.html#jls-17.2.1), `Object.wait()` can return spuriously — without a corresponding `notify()`/`notifyAll()`. The standard pattern is to use a `while` loop instead of `if`:
```java
synchronized(fLock) {
while (fQueue.isEmpty() && !fClosed) {
fLock.wait();
}
}
```
This ensures the condition is rechecked after any wakeup. The `!fClosed` guard also avoids waiting forever if the stream was closed while waiting.
Found via SpotBugs static analysis (WA_NOT_IN_LOOP).
Contributor guide
Research direction
Start at InputStreamMonitor.writeNext() around line 189 and inspect the surrounding queue and stream-close handling. Check the SpotBugs WA_NOT_IN_LOOP finding, then verify that wakeups recheck the queue and that a closed stream cannot wait forever.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 76/100