8266014: Regression brought by optimization done with JDK-4926314
Reviewed-by: alanb, naoto
This commit is contained in:
parent
6bb71d9e25
commit
2a03739530
@ -188,9 +188,7 @@ public abstract class Reader implements Readable, Closeable {
|
||||
if (target.hasArray()) {
|
||||
char[] cbuf = target.array();
|
||||
int pos = target.position();
|
||||
int rem = target.limit() - pos;
|
||||
if (rem <= 0)
|
||||
return -1;
|
||||
int rem = Math.max(target.limit() - pos, 0);
|
||||
int off = target.arrayOffset() + pos;
|
||||
nread = this.read(cbuf, off, rem);
|
||||
if (nread > 0)
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4926314
|
||||
* @bug 4926314 8266014
|
||||
* @summary Test for Reader#read(CharBuffer).
|
||||
* @run testng ReadCharBuffer
|
||||
*/
|
||||
@ -33,7 +33,10 @@ import org.testng.annotations.Test;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.CharArrayReader;
|
||||
import java.io.Reader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.util.Arrays;
|
||||
@ -98,6 +101,19 @@ public class ReadCharBuffer {
|
||||
assertEquals(buffer.toString(), expected.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readZeroLength() {
|
||||
char[] buf = new char[] {1, 2, 3};
|
||||
BufferedReader r = new BufferedReader(new CharArrayReader(buf));
|
||||
int n = -1;
|
||||
try {
|
||||
n = r.read(CharBuffer.allocate(0));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
assertEquals(n, 0);
|
||||
}
|
||||
|
||||
private void fillBuffer(CharBuffer buffer) {
|
||||
char[] filler = new char[buffer.remaining()];
|
||||
Arrays.fill(filler, 'x');
|
||||
|
Loading…
Reference in New Issue
Block a user