Summary
-------
Add `@throws NonWritableChannelException` to the `tryLock()` and `write()` methods of `java.nio.channels.FileChannel`.
Problem
-------
If a `tryLock()` or `write()` method is invoked on a `java.nio.channels.FileChannel` which has been opened with read-only access, then a `java.nio.channels.NonWritableChannelException` is thrown but the documentation does not indicate this.
Solution
--------
Add `@throws NonWritableChannelException` to the indicated methods.
Specification
-------------
Note that for `tryLock(long,long,boolean)`, the `boolean` parameter `shared` is referred to. The other `@throws` are all the same and do not mention any parameter.
@@ -403,6 +406,9 @@ public abstract class FileChannel
* 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
*/
public abstract int write(ByteBuffer src) throws IOException;
@@ -417,6 +423,9 @@ public abstract class FileChannel
* 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
*/
public abstract long write(ByteBuffer[] srcs, int offset, int length)
throws IOException;
@@ -431,6 +440,9 @@ public abstract class FileChannel
* 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
*/
public final long write(ByteBuffer[] srcs) throws IOException {
return write(srcs, 0, srcs.length);
@@ -1030,7 +1042,7 @@ public abstract class FileChannel
* region
*
* @throws NonReadableChannelException
- * If {@code shared} is {@code true} this channel was not
+ * If {@code shared} is {@code true} but this channel was not
* opened for reading
*
* @throws NonWritableChannelException
@@ -1148,6 +1160,14 @@ public abstract class FileChannel
* blocked in this method and is attempting to lock an overlapping
* region of the same file
*
+ * @throws NonReadableChannelException
+ * If {@code shared} is {@code true} but this channel was not
+ * opened for reading
+ *
+ * @throws NonWritableChannelException
+ * If {@code shared} is {@code false} but this channel was not
+ * opened for writing
+ *
* @throws IOException
* If some other I/O error occurs
*
@@ -1180,6 +1200,9 @@ public abstract class FileChannel
* blocked in this method and is attempting to lock an overlapping
* region
*
+ * @throws NonWritableChannelException
+ * If this channel was not opened for writing
+ *
* @throws IOException
* If some other I/O error occurs
*