Skip to content

Commit

Permalink
8264777: Handle readNBytes(0): src/test
Browse files Browse the repository at this point in the history
  • Loading branch information
bplb committed May 10, 2021
1 parent 5272d5e commit 4fae020
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/io/FileInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ public byte[] readAllBytes() throws IOException {
public byte[] readNBytes(int len) throws IOException {
if (len < 0)
throw new IllegalArgumentException("len < 0");
if (len == 0)
return new byte[0];

long length = length();
long position = position();
Expand Down
5 changes: 4 additions & 1 deletion test/jdk/java/io/FileInputStream/ReadXBytes.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ public static void main(String args[]) throws IOException {
int pos = RND.nextInt(size);
int len = RND.nextInt(size - pos);
fis.getChannel().position(pos);
byte[] nbytes = fis.readNBytes(len);
byte[] nbytes = fis.readNBytes(0);
if (nbytes.length != 0)
throw new RuntimeException("readNBytes() zero length");
nbytes = fis.readNBytes(len);
if (nbytes.length != len)
throw new RuntimeException("readNBytes() length");
if (!Arrays.equals(nbytes, 0, len, bytes, pos, pos + len))
Expand Down

0 comments on commit 4fae020

Please sign in to comment.