Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8303474

(fc) FileChannel::transferFrom should support position > size()

    XMLWordPrintable

Details

    • CSR
    • Resolution: Approved
    • P4
    • 21
    • core-libs
    • None
    • behavioral
    • minimal
    • It is unlikely that expecting zero bytes to be written is a relied upon behavior.
    • Java API
    • SE

    Description

      Summary

      Change java.nio.channels.FileChannel::transferFrom to extend the channel's file if position > size() instead of writing no bytes.

      Problem

      Currently passing a position value which is greater than FileChannel::size to FileChannel::transferFrom results in no bytes being written. This is inconsistent with FileChannel::write(ByteBuffer,long) which extends the channel's file if position > size().

      Solution

      Modify FileChannel::transferFrom to extend the channel's file when position > size() in the same manner as the positional FileChannel:write.

      Specification

          --- a/src/java.base/share/classes/java/nio/channels/FileChannel.java
          +++ b/src/java.base/share/classes/java/nio/channels/FileChannel.java
          @@ -701,8 +701,10 @@ public abstract class FileChannel
            * source has reached end-of-stream.
            *
            * <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
      -     * transferred.  If the source channel has a position then bytes are read
      +     * 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.  If the source channel has a position then bytes are read
            * starting at that position and then the position is incremented by the
            * number of bytes read.
            *

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              bpb Brian Burkhalter
              Alan Bateman
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: