Summary
Change the specification of the java.nio.channels.FileChannel
methods transferTo
, read(ByteBuffer,long)
, and write(ByteBuffer,long)
to state that the behavior described for a position greater than the file's current size also applies when the position equals the current size.
Problem
The description of the position
parameter of the indicated methods is insufficiently clear when this parameter equals the file's size.
Solution
Make the specification of the indicated methods state that the behavior is the same for positions beyond end of file as for position == size()
. This change will bring the specification into line with the implementation.
Specification
--- a/src/java.base/share/classes/java/nio/channels/FileChannel.java
+++ b/src/java.base/share/classes/java/nio/channels/FileChannel.java
@@ -633,7 +633,7 @@ public final long write(ByteBuffer[] srcs) throws IOException {
* bytes free in its output buffer.
*
* <p> This method does not modify this channel's position. If the given
- * position is greater than the file's current size then no bytes are
+ * position is greater than or equal to the file's current size then no bytes are
* transferred. If the target channel has a position then bytes are
* written starting at that position and then the position is incremented
* by the number of bytes written.
@@ -761,7 +761,7 @@ public abstract long transferFrom(ReadableByteChannel src,
* #read(ByteBuffer)} method, except that bytes are read starting at the
* given file position rather than at the channel's current position. This
* method does not modify this channel's position. If the given position
- * is greater than the file's current size then no bytes are read. </p>
+ * is greater than or equal to the file's current size then no bytes are read. </p>
*
* @param dst
* The buffer into which bytes are to be transferred
@@ -806,7 +806,7 @@ public abstract long transferFrom(ReadableByteChannel src,
* #write(ByteBuffer)} method, except that bytes are written starting at
* the given file position rather than at the channel's current position.
* This method does not modify this channel's position. If the given
- * position is greater than the file's current size then the file will be
+ * position is greater than or equal to the file's current size then the file will be
* grown to accommodate the new bytes; the values of any bytes between the
* previous end-of-file and the newly-written bytes are unspecified. </p>
- csr of
-
JDK-8029370 (fc) FileChannel javadoc not clear for cases where position == size
-
- Resolved
-