JDK-8245185 : Files.move() with REPLACE_EXISTING fails without Exception on certain Filesystem
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 14
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2020-05-12
  • Updated: 2020-11-18
  • Resolved: 2020-05-18
Description
ADDITIONAL SYSTEM INFORMATION :
OS:  Windows 10 Pro N, Version 1909
Env:
 - PROCESSOR_IDENTIFIER: AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
 - OS: Windows_NT

A DESCRIPTION OF THE PROBLEM :
Adding StandardCopyOption.REPLACE_EXISTING to the Files.move() method leads to a silent fail (i.e. without any exception) if
- both source and target are pointing to files on a special file system
- the target already exists (i.e. must be replaced)

An example file system is Google Drive File Stream (GDFS).

Side note: This can be easily tested with the jshell.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create files `foo.txt` and `bar.txt` on a GDFS volume.
2. Write "Hello World" into `foo.txt`
3. Move `foo.txt` to `bar.txt` via Files.move() with flag REPLACE_EXISTING

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful move (`foo.txt` is not present anymore, `bar.txt` contains "Hello World") or IOException is thrown
ACTUAL -
Move fails without Exception, i.e. `foo.txt` still exists and `bar.txt` has a size of 0 Bytes.

---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.BasicFileAttributes;

public class Test {

	public static void main(String [] args) throws IOException {
		//pointing to a Google Drive File Stream location
		Path root = Path.of("L:\\My Drive\\");

		Path foo = root.resolve("foo.txt");
		Files.writeString(foo, "Hello World", StandardOpenOption.CREATE, StandardOpenOption.WRITE);

		Path bar = root.resolve("bar.txt");
		Files.createFile(bar);

		Files.move(foo, bar, StandardCopyOption.REPLACE_EXISTING);

		//this should fail
		Files.readAttributes(foo, BasicFileAttributes.class);
		//this should be non zero
		System.out.println(Files.readAttributes(bar, BasicFileAttributes.class).size());

	}

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

CUSTOMER SUBMITTED WORKAROUND :
Delete target if it exists ( e.g. with the Files.deleteIfExists() method) before move operation.

FREQUENCY : always



Comments
Test Result =========== 14.0.1: as expected, `foo.txt` is not present anymore, `bar.txt` contains "Hello World" and has a size of 11 bytes. 15ea23: as expected, `foo.txt` is not present anymore, `bar.txt` contains "Hello World" and has a size of 11 bytes.
18-05-2020

Would be useful to know if other Windows applications have the same issue, might need to be reported to Google Drive.
18-05-2020

The Google drive app can not display Traditional Chinese correctly on my Windows 10 machine. But I believe to manipulate files and folders on Google Drive the specific APIs from Google are needed. This incident should be close as not an issue.
15-05-2020