eclipse-jdt / eclipse-jdt/eclipse.jdt.debug

Redirecting `stdin` for a run configuration on Windows hangs when buffered reader reaches EOF.

Open
#736 6 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
23
Forks
68
Avg merge
1d 4h
Merged PRs (30d)
13

Description

I have a simple Java CLI `my-cli` that reads lines from `stdin` until the end of the stream is reached:

```java
LineNumberReader reader = new LineNumberReader(new InputStreamReader(System.in));
String line;
while((line = reader.readLine()) != null) {
//TODO process the line
}
```

On Windows 10 from the command line, if I run `my-cli < test-input.txt`, then the input is rerouted and the program runs normally. The above loop ends when the end of the file (from which `stdin` is redirected) is reached.

I should be able to reproduce this behavior in Eclipse by assigning `stdin` to a file in the run configuration, in the setting window shown in an [answer](https://stackoverflow.com/a/31287752) to [Redirect stdin from a file in eclipse with run configuration](https://stackoverflow.com/questions/31234646/redirect-stdin-from-a-file-in-eclipse-with-run-configuration).

Unfortunately the Eclipse implementation seems to never detect the end of the file. Instead, when running the program inside the IDE, the call to `reader.readLine()` hangs when the end of the file is reached. It seems to hang in `java.io.FileInputStream.read(byte[] b, int off, int len)`, in the call to `return readBytes(b, off, len)` below:

```java
@Override
public int read(byte[] b, int off, int len) throws IOException {
long comp = Blocker.begin();
try {
return readBytes(b, off, len);
} finally {
Blocker.end(comp);
}
}
```

Here's the relevant part of the stack of the hung thread:

```
FileInputStream.readBytes(byte[], int, int) line: not available [native method]
FileInputStream.read(byte[], int, int) line: 287
BufferedInputStream.read1(byte[], int, int) line: 345
BufferedInputStream.implRead(byte[], int, int) line: 420
BufferedInputStream.read(byte[], int, int) line: 399
StreamDecoder.readBytes() line: 350
StreamDecoder.implRead(char[], int, int) line: 393
StreamDecoder.lockedRead(char[], int, int) line: 217
StreamDecoder.read(char[], int, int) line: 171
InputStreamReader.read(char[], int, int) line: 188
LineNumberReader(BufferedReader).fill() line: 160
LineNumberReader(BufferedReader).implReadLine(boolean, boolean[]) line: 370
LineNumberReader(BufferedReader).readLine(boolean, boolean[]) line: 353
LineNumberReader.readLine() line: 250
```

I'm using Java 24 on Eclipse 2025-06 (4.36.0).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.