# HG changeset patch # User bpb # Date 1509729507 25200 # Node ID 24e43fd1ad69d579374881ff3113676df7b0ce29 # Parent 843c071258a65ff58ced4353b14283653ed57ed5 8190500: (ch) ReadableByteChannelImpl::read and WritableByteChannelImpl::write might not throw ClosedChannelException as specified Summary: Explicitly verify that the channel is open Reviewed-by: alanb diff -r 843c071258a6 -r 24e43fd1ad69 src/java.base/share/classes/java/nio/channels/Channels.java --- a/src/java.base/share/classes/java/nio/channels/Channels.java Fri Nov 03 13:03:10 2017 -0400 +++ b/src/java.base/share/classes/java/nio/channels/Channels.java Fri Nov 03 10:18:27 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2017, 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 @@ -368,6 +368,10 @@ @Override public int read(ByteBuffer dst) throws IOException { + if (!isOpen()) { + throw new ClosedChannelException(); + } + int len = dst.remaining(); int totalRead = 0; int bytesRead = 0; @@ -442,6 +446,10 @@ @Override public int write(ByteBuffer src) throws IOException { + if (!isOpen()) { + throw new ClosedChannelException(); + } + int len = src.remaining(); int totalWritten = 0; synchronized (writeLock) { diff -r 843c071258a6 -r 24e43fd1ad69 test/jdk/java/nio/channels/Channels/Basic.java --- a/test/jdk/java/nio/channels/Channels/Basic.java Fri Nov 03 13:03:10 2017 -0400 +++ b/test/jdk/java/nio/channels/Channels/Basic.java Fri Nov 03 10:18:27 2017 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2017, 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 @@ -167,6 +167,11 @@ readAndCheck(blah); blah.delete(); + testNewChannelWriteAfterClose(blah); + + testNewChannelReadAfterClose(blah); + blah.delete(); + writeOut(blah, ITERATIONS); testNewChannelIn(blah); test4481572(blah); @@ -255,6 +260,7 @@ private static void testNewChannelOut(File blah) throws Exception { ExtendedFileOutputStream fos = new ExtendedFileOutputStream(blah); WritableByteChannel wbc = Channels.newChannel(fos); + for (int i=0; i