Bug in Files.createDirectories(Path, FileAttribute<?>...)

Christian Schlichtherle christian at schlichtherle.de
Sat Jan 18 08:44:24 PST 2014


Hi everyone,

running the following program:

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ShouldNotThrowException {
    public static void main(String[] args) throws IOException {
        Files.createDirectories(Paths.get("/"));
    }
}
produces the following output:

Exception in thread "main" java.io.IOException: Root directory does not exist
	at java.nio.file.Files.createDirectories(Files.java:711)
	at ShouldNotThrowException.main(ShouldNotThrowException.java:7)
Apart from the fact that the exception message is bogus (of course my root directory exists :-)), the Javadoc for Files.createDirectories(Path, FileAttribute<?>…) reads:
Unlike the {@link #createDirectory createDirectory} method, an exception is not thrown if the directory could not be created because it already exists.

So this is a bug. This has been discovered because it affected a user of TrueZIP, a virtual file system for archive files I’ve created. The respective ticket is at https://java.net/jira/browse/TRUEZIP-339 .

Best regards,
Christian Schlichtherle

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-discuss/attachments/20140118/454f5454/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 495 bytes
Desc: Message signed with OpenPGP using GPGMail
Url : http://mail.openjdk.java.net/pipermail/nio-discuss/attachments/20140118/454f5454/signature.asc 


More information about the nio-discuss mailing list