8275149: (ch) ReadableByteChannel returned by Channels.newChannel(InputStream) throws ReadOnlyBufferException

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2021-10-15 22:58:21 +00:00
parent 831802ddb1
commit 7fc3a8d052
2 changed files with 12 additions and 2 deletions

View File

@ -295,6 +295,9 @@ public final class Channels {
if (!isOpen()) {
throw new ClosedChannelException();
}
if (dst.isReadOnly()) {
throw new IllegalArgumentException();
}
int len = dst.remaining();
int totalRead = 0;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,7 +22,7 @@
*/
/* @test
* @bug 4417152 4481572 6248930 6725399 6884800 8220477
* @bug 4417152 4481572 6248930 6725399 6884800 8220477 8275149
* @summary Test Channels basic functionality
*/
@ -296,6 +296,13 @@ public class Basic {
byte data[] = new byte[messageSize+1];
ByteBuffer bb = ByteBuffer.wrap(data);
try {
rbc.read(bb.asReadOnlyBuffer());
throw new RuntimeException("IllegalArgumentException not thrown");
} catch (IllegalArgumentException expected) {
// ignore it
}
int bytesRead = 0;
int totalRead = 0;
while (bytesRead != -1) {