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

(fc spec) Unclear spec for FileChannel.force

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • behavioral
    • minimal
    • Verbiage change documents existing, long standing behavior.
    • Java API
    • SE

      Summary

      Clarify that modifications to a FileChannel's file made via methods of a FileOutputStream or RandomAccessFile from which the channel was obtained using getChannel() are also subject to the effects of FileChannel.force().

      Problem

      Currently the specification of FileChannel.force() states only

      This method is only guaranteed to force changes that were made to this channel's file via the methods defined in this class.

      which does not cover the cases where changes made via parent FileOutputStream and RandomAccessFile methods will also be forced.

      Solution

      Change the sentence mentioned in the problem statement above to:

      This method is only guaranteed to force changes that were made to this channel's file via the methods defined in this class, or the methods defined by FileOutputStream or RandomAccessFile when the channel was obtained with the getChannel method.

      Specification

      --- a/src/java.base/share/classes/java/nio/channels/FileChannel.java
      +++ b/src/java.base/share/classes/java/nio/channels/FileChannel.java
      @@ -554,7 +554,9 @@ public abstract class FileChannel
            * actually done is system-dependent and is therefore unspecified.
            *
            * <p> This method is only guaranteed to force changes that were made to
      -     * this channel's file via the methods defined in this class.  It may or
      +     * this channel's file via the methods defined in this class, or the methods
      +     * defined by {@link FileOutputStream} or {@link RandomAccessFile} when the
      +     * channel was obtained with the {@code getChannel} method. It may or
            * may not force changes that were made by modifying the content of a
            * {@link MappedByteBuffer <i>mapped byte buffer</i>} obtained by
            * invoking the {@link #map map} method.  Invoking the {@link

            bpb Brian Burkhalter
            nthompsosunw Nathanael Thompson (Inactive)
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: