8287003: InputStreamReader::read() can return zero despite writing a char in the buffer

Reviewed-by: jpai, rriggs
This commit is contained in:
Brian Burkhalter 2022-05-27 15:23:01 +00:00
parent 63eb0b7e86
commit 6520843f86
2 changed files with 32 additions and 9 deletions

View file

@ -215,7 +215,13 @@ public class StreamDecoder extends Reader {
return n + 1;
}
return n + implRead(cbuf, off, off + len);
// Read remaining characters
int nr = implRead(cbuf, off, off + len);
// At this point, n is either 1 if a leftover character was read,
// or 0 if no leftover character was read. If n is 1 and nr is -1,
// indicating EOF, then we don't return their sum as this loses data.
return (nr < 0) ? (n == 1 ? 1 : nr) : (n + nr);
}
public boolean ready() throws IOException {