Summary
Add @throws NonReadableChannelException
and @throws NonWritableChannelException
to the read
and write
methods, respectively, of java.nio.channels.SeekableByteChannel
and java.nio.channels.FileChannel
where these tags are incorrectly missing.
Problem
SeekableByteChannel
and FileChannel
are insufficiently explicit about their read
and write
methods throwing NonReadableChannelException
and NonWritableChannelException
, respectively` by assuming that developers will have read the interface specifications that these methods override.
Solution
Add @throws NonReadableChannelException {@inheritDoc}
and @throws NonWritableChannelException {@inheritDoc}
where missing.
Specification
diff a/src/java.base/share/classes/java/nio/channels/FileChannel.java b/src/java.base/share/classes/java/nio/channels/FileChannel.java
--- a/src/java.base/share/classes/java/nio/channels/FileChannel.java
+++ b/src/java.base/share/classes/java/nio/channels/FileChannel.java
@@ -378,10 +378,11 @@
* ReadableByteChannel} interface. </p>
*
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonReadableChannelException {@inheritDoc}
*/
public abstract int read(ByteBuffer dst) throws IOException;
/**
* Reads a sequence of bytes from this channel into a subsequence of the
@@ -393,10 +394,11 @@
* ScatteringByteChannel} interface. </p>
*
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonReadableChannelException {@inheritDoc}
*/
public abstract long read(ByteBuffer[] dsts, int offset, int length)
throws IOException;
/**
@@ -408,10 +410,11 @@
* ScatteringByteChannel} interface. </p>
*
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonReadableChannelException {@inheritDoc}
*/
public final long read(ByteBuffer[] dsts) throws IOException {
return read(dsts, 0, dsts.length);
}
@@ -424,16 +427,14 @@
* to accommodate the written bytes, and then the file position is updated
* with the number of bytes actually written. Otherwise this method
* behaves exactly as specified by the {@link WritableByteChannel}
* interface. </p>
*
- * @throws NonWritableChannelException
- * If this channel was not opened for writing
- *
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonWritableChannelException {@inheritDoc}
*/
public abstract int write(ByteBuffer src) throws IOException;
/**
* Writes a sequence of bytes to this channel from a subsequence of the
@@ -445,16 +446,14 @@
* to accommodate the written bytes, and then the file position is updated
* with the number of bytes actually written. Otherwise this method
* behaves exactly as specified in the {@link GatheringByteChannel}
* interface. </p>
*
- * @throws NonWritableChannelException
- * If this channel was not opened for writing
- *
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonWritableChannelException {@inheritDoc}
*/
public abstract long write(ByteBuffer[] srcs, int offset, int length)
throws IOException;
/**
@@ -466,16 +465,14 @@
* to accommodate the written bytes, and then the file position is updated
* with the number of bytes actually written. Otherwise this method
* behaves exactly as specified in the {@link GatheringByteChannel}
* interface. </p>
*
- * @throws NonWritableChannelException
- * If this channel was not opened for writing
- *
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonWritableChannelException {@inheritDoc}
*/
public final long write(ByteBuffer[] srcs) throws IOException {
return write(srcs, 0, srcs.length);
}
diff a/src/java.base/share/classes/java/nio/channels/SeekableByteChannel.java b/src/java.base/share/classes/java/nio/channels/SeekableByteChannel.java
--- a/src/java.base/share/classes/java/nio/channels/SeekableByteChannel.java
+++ b/src/java.base/share/classes/java/nio/channels/SeekableByteChannel.java
@@ -62,10 +62,11 @@
* ReadableByteChannel} interface.
*
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonReadableChannelException {@inheritDoc}
*/
@Override
int read(ByteBuffer dst) throws IOException;
/**
@@ -81,10 +82,11 @@
* the {@link WritableByteChannel} interface.
*
* @throws ClosedChannelException {@inheritDoc}
* @throws AsynchronousCloseException {@inheritDoc}
* @throws ClosedByInterruptException {@inheritDoc}
+ * @throws NonWritableChannelException {@inheritDoc}
*/
@Override
int write(ByteBuffer src) throws IOException;
/**
- csr of
-
JDK-7132279 (ch) SeekableByteChannel operation may throw Non{Readable,Writable}ChannelException
-
- Resolved
-