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

ATOMIC_MOVE will not throw FileAlreadyExistsException when file already exists

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_144"
      Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      Example:
      I have a "/tmp/file.txt" and "/tmp/file.txt.tmp".

      I would expect that java command
      "Files.move(originalPath, finalPath, StandardCopyOption.ATOMIC_MOVE)"
      would only succeed when both files have the same hash and filesize (when the files are identical).

      When the files differ I would expect a FileAlreadyExistsException.

      However the FileAlreadyExistsException is only thrown when ATOMIC_MOVE is not enabled.

      In my opinion the java API is not very clear in this respect. The java API states: "If the target file exists then it is implementation specific if the existing file is replaced or this method fails by throwing an IOException."

      Possible solutions:
      - change the implementation that it matches the expectation
      - more understandable java api, so that it mentions the fact that FileAlreadyExistsException might not be thrown in some implementations.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      Not using Atomic move option.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: