JDK-4774868 : (fc spec) Unclear spec for FileChannel.force
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-11-06
  • Updated: 2022-02-03
  • Resolved: 2022-01-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 19
19 b08Fixed
Related Reports
CSR :  
Relates :  
Relates :  
Description
Name: nt126004			Date: 11/06/2002


FULL PRODUCT VERSION :
Javadoc in 1.4.0 and 1.4.1

A DESCRIPTION OF THE PROBLEM :
Unclear or inconsistent description of behavior in
java.nio.FileChannel.force() javadoc.

  From FileChannel.force()

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

This implies to me that writes on the class that was used
to obtain the FileChannel object (e.g. RandomAccessFile)
are *not* guaranteed to be forced by this call.

But, the class description for FileChannel includes this

"The state of a file channel is intimately connected to
that of the object whose getChannel method returned the
channel. Changing the channel's position, whether
explicitly or by reading or writing bytes, will change the
file position of the originating object, and vice versa.
Changing the file's length via the file channel will change
the length seen via the originating object, and vice versa.
Changing the file's content by writing bytes will change
the content seen by the originating object, and vice
versa. "

If the RandomAccessFile and FileChannel objects
are "intimately connected " then I would expect force() to
force data written by methods of the RandomAccessFile.

Does this inconsistency actually exist?

REPRODUCIBILITY :
This bug can be reproduced always.
(Review ID: 165001) 
======================================================================

Comments
Changeset: 95ee9bf7 Author: Brian Burkhalter <bpb@openjdk.org> Date: 2022-01-28 17:12:42 +0000 URL: https://git.openjdk.java.net/jdk/commit/95ee9bf7be40572e768cf6213c03ca183b8ad886
28-01-2022

A pull request was submitted for review. URL: https://git.openjdk.java.net/jdk/pull/7207 Date: 2022-01-25 02:12:38 +0000
25-01-2022

If a FileChannel is derived from a FileOutputStream or RandomAccessFile by invoking the getChannel() method, then it shares a file descriptor with the object from which it was derived. Consequently any changes made to the file using methods defined on the parent object should be forced as well. The verbiage describing force() should be updated to reflect this.
25-01-2022