6766844: ByteArrayInputStream#read with a byte array of length 0 not consistent with InputStream when at EOF
Reviewed-by: naoto, lancea, joehw
This commit is contained in:
parent
9e75f922b1
commit
f46a917270
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1994, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -156,6 +156,10 @@ public class ByteArrayInputStream extends InputStream {
|
|||||||
* {@code b[off+k-1]} in the manner performed by {@code System.arraycopy}.
|
* {@code b[off+k-1]} in the manner performed by {@code System.arraycopy}.
|
||||||
* The value {@code k} is added into {@code pos} and {@code k} is returned.
|
* The value {@code k} is added into {@code pos} and {@code k} is returned.
|
||||||
* <p>
|
* <p>
|
||||||
|
* Unlike the {@link InputStream#read(byte[],int,int) overridden method}
|
||||||
|
* of {@code InputStream}, this method returns {@code -1} instead of zero
|
||||||
|
* if the end of the stream has been reached and {@code len == 0}.
|
||||||
|
* <p>
|
||||||
* This {@code read} method cannot block.
|
* This {@code read} method cannot block.
|
||||||
*
|
*
|
||||||
* @param b the buffer into which the data is read.
|
* @param b the buffer into which the data is read.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -33,7 +33,7 @@ import jdk.test.lib.RandomFactory;
|
|||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @build jdk.test.lib.RandomFactory
|
* @build jdk.test.lib.RandomFactory
|
||||||
* @run main ReadAllReadNTransferTo
|
* @run main ReadAllReadNTransferTo
|
||||||
* @bug 8180451
|
* @bug 6766844 8180451
|
||||||
* @summary Verify ByteArrayInputStream readAllBytes, readNBytes, and transferTo
|
* @summary Verify ByteArrayInputStream readAllBytes, readNBytes, and transferTo
|
||||||
* @key randomness
|
* @key randomness
|
||||||
*/
|
*/
|
||||||
@ -48,8 +48,16 @@ public class ReadAllReadNTransferTo {
|
|||||||
int position = random.nextInt(SIZE/2);
|
int position = random.nextInt(SIZE/2);
|
||||||
int size = random.nextInt(SIZE - position);
|
int size = random.nextInt(SIZE - position);
|
||||||
|
|
||||||
ByteArrayInputStream bais =
|
ByteArrayInputStream bais = new ByteArrayInputStream(buf);
|
||||||
new ByteArrayInputStream(buf, position, size);
|
bais.readAllBytes();
|
||||||
|
if (bais.read(new byte[0]) != -1) {
|
||||||
|
throw new RuntimeException("read(byte[]) did not return -1");
|
||||||
|
}
|
||||||
|
if (bais.read(new byte[1], 0, 0) != -1) {
|
||||||
|
throw new RuntimeException("read(byte[],int,int) did not return -1");
|
||||||
|
}
|
||||||
|
|
||||||
|
bais = new ByteArrayInputStream(buf, position, size);
|
||||||
int off = size < 2 ? 0 : random.nextInt(size / 2);
|
int off = size < 2 ? 0 : random.nextInt(size / 2);
|
||||||
int len = size - off < 1 ? 0 : random.nextInt(size - off);
|
int len = size - off < 1 ? 0 : random.nextInt(size - off);
|
||||||
|
|
||||||
@ -72,7 +80,6 @@ public class ReadAllReadNTransferTo {
|
|||||||
throw new RuntimeException("readAllBytes content");
|
throw new RuntimeException("readAllBytes content");
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX transferTo()
|
|
||||||
bais = new ByteArrayInputStream(buf);
|
bais = new ByteArrayInputStream(buf);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(buf.length);
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(buf.length);
|
||||||
if (bais.transferTo(baos) != buf.length) {
|
if (bais.transferTo(baos) != buf.length) {
|
||||||
|
Loading…
Reference in New Issue
Block a user