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

Files.move() with REPLACE_EXISTING fails without Exception on certain Filesystem

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Cannot Reproduce
    • Affects Version/s: 14
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      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


        Attachments

          Activity

            People

            • Assignee:
              tongwan Andrew Wang
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: