JDK-8232861 : (fc) FileChannel.force fails on WebDAV file systems (macOS)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 9,13
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2019-10-08
  • Updated: 2021-04-15
  • Resolved: 2021-04-09
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 17
17 b18Fixed
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
macOS 10.14.6, Tested with Oracle JDK 8u202, 8u221 and 13

A DESCRIPTION OF THE PROBLEM :
Beginning with Java 9 it is no longer possible to call force() on a FileChannel pointing to a file on a mounted WebDAV drive (similar reports for CIFS drives on Linux that I can not confirm).

REGRESSION : Last worked in version 8u221

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Mount a WebDAV-Drive (in Finder press ������������K). For Testing you can use a URL obtained from the upper right corner of webdavserver.com
2. Run attached test class, provide an absolute path to a any existing or nonexisting file inside the mounted drive as arg[0]

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception
ACTUAL -
java.io.IOException: Invalid argument
	at java.base/sun.nio.ch.FileDispatcherImpl.force0(Native Method)
	at java.base/sun.nio.ch.FileDispatcherImpl.force(FileDispatcherImpl.java:82)
	at java.base/sun.nio.ch.FileChannelImpl.force(FileChannelImpl.java:461)

---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

public class ChannelForceTest {
	
	public static void main(String args[]) {
		if (args.length != 1) {
			System.out.println("Run with arg[0] being an absolute path to a webdav-mounted directory");
			System.exit(1);
		}
		
		Path p = Paths.get(args[0]);
		try (FileChannel ch = FileChannel.open(p, StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
			ch.force(true); // fails
			System.out.println("No exception under JDK 8");
		} catch (IOException e) {
			System.out.println("Exception under JDK 9+");
			e.printStackTrace();
		}
	}

}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Changeset: 6de0bb20 Author: Brian Burkhalter <bpb@openjdk.org> Date: 2021-04-09 15:31:11 +0000 URL: https://git.openjdk.java.net/jdk/commit/6de0bb20
09-04-2021

The bytes written appear to be correct but fcntl() has error ENOTTY.
06-04-2021

In JDK 17-internal the following is observed: $ java ChannelForceTest /Volumes/User59df9d5/nonexisting Exception under JDK 9+ java.io.IOException: Inappropriate ioctl for device at java.base/sun.nio.ch.FileDispatcherImpl.force0(Native Method) at java.base/sun.nio.ch.FileDispatcherImpl.force(FileDispatcherImpl.java:82) at java.base/sun.nio.ch.FileChannelImpl.force(FileChannelImpl.java:465) at ChannelForceTest.main(ChannelForceTest.java:17)
05-04-2021

The FileChannel.force method was fixed in JDK 9 to use fcntl(fd, F_FULLFSYNC), all the details are in JDK-8080589. I assume it never worked with WebDAV file systems either. Not sure what we can do here, except just report the issue to Apple.
23-10-2019