Wrong exception thrown?

Andrew John Hughes gnu_andrew at member.fsf.org
Sat Aug 29 19:26:45 PDT 2009

2009/8/29 John Hendrikx <hjohn at xs4all.nl>:
> 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 +
> I would expect the FileAlreadyExistsException to be thrown.  It's not a
> permission issue (and the files are not 'read only').

Given the stack trace, it seems like this inaccurate error comes from
Windows rather than OpenJDK (the last two methods translate Windows
error values into exceptions).
To get the appropriate FileAlreadYExistsException, implMoveTo would
need to explicitly check for existence of the destination before doing
the move at the OS level.
Andrew :-)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

Support Free Java!
Contribute to GNU Classpath and the OpenJDK

PGP Key: 94EFD9D8 (http://subkeys.pgp.net)
Fingerprint: F8EF F1EA 401E 2E60 15FA  7927 142C 2591 94EF D9D8

More information about the nio-dev mailing list