Wrong exception thrown?

Alan Bateman Alan.Bateman at Sun.COM
Tue Sep 1 01:28:08 PDT 2009


John Hendrikx wrote:
> Exception in  thread "Thread-8": java.nio.file.AccessDeniedException:
> c:\Copy\Macros2 -> c:\Copy2\Macros2
> 	at
> sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
> 	at
> sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
> 	at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:301)
> 	at sun.nio.fs.WindowsPath.implMoveTo(WindowsPath.java:1004)
> 	at sun.nio.fs.AbstractPath.moveTo(AbstractPath.java:201)
> 	at
> hs.filemanager.transfer.RenameFileVisitor.rename(RenameFileVisitor.java:67)
>
> This occurs when moveTo() is called with the arguments indicated +
> ATOMIC_MOVE.
>
> I would expect the FileAlreadyExistsException to be thrown.  It's not a
> permission issue (and the files are not 'read only').
>
>   
When the ATOMIC_MOVE option is specified then it is allowed to replace 
the target file if it exists. In other words, it is not required to fail 
if the target exists. An implementation can't first check if the file 
exists because the overall operation must be atomic. One annoyance, as 
Andrew suspected,  is that Windows returns its equivalent of "access 
denied" for both the permission denied case and the case that the target 
is a directory. Is C:\Copy2\Macros2 is a directory?

-Alan.


More information about the nio-dev mailing list