Skip to main content

[truezip-issues] [JIRA] Resolved: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

  • From: "Christian Schlichtherle (JIRA)" <jira-no-reply@...>
  • To: issues@...
  • Subject: [truezip-issues] [JIRA] Resolved: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)
  • Date: Sat, 18 Jan 2014 16:37:49 +0000 (UTC)
  • Auto-submitted: auto-generated


     [ 
https://java.net/jira/browse/TRUEZIP-339?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Christian Schlichtherle resolved TRUEZIP-339.
---------------------------------------------

    Resolution: Invalid

When changing the path to "/TestTrueZipRootIssue.zip" and running the program 
on Mac OS X, I do get pretty much the same stack trace:

{noformat}
java.nio.file.FileAlreadyExistsException: /TestTrueZipRootIssue.zip
        at 
de.schlichtherle.truezip.nio.file.TFileSystem.createDirectory(TFileSystem.java:362)
        at 
de.schlichtherle.truezip.nio.file.TPath.createDirectory(TPath.java:970)
        at 
de.schlichtherle.truezip.nio.file.TFileSystemProvider.createDirectory(TFileSystemProvider.java:315)
        at java.nio.file.Files.createDirectory(Files.java:628)
        at QTrueZipExportToRoot.main(QTrueZipExportToRoot.java:28)
Caused by: java.io.IOException: Root directory does not exist
        at java.nio.file.Files.createDirectories(Files.java:711)
        at 
de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.begin(FileOutputSocket.java:109)
        at 
de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.newOutputStream(FileOutputSocket.java:222)
        at 
de.schlichtherle.truezip.fs.archive.zip.OptionOutputSocket.newOutputStream(OptionOutputSocket.java:48)
        at 
de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:586)
        at 
de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop0(ZipDriver.java:576)
        at 
de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:561)
        at 
de.schlichtherle.truezip.fs.FsTargetArchiveController.makeOutputArchive(FsTargetArchiveController.java:247)
        at 
de.schlichtherle.truezip.fs.FsTargetArchiveController.mount0(FsTargetArchiveController.java:182)
        at 
de.schlichtherle.truezip.fs.FsTargetArchiveController.mount(FsTargetArchiveController.java:155)
        at 
de.schlichtherle.truezip.fs.FsFileSystemArchiveController$ResetFileSystem.autoMount(FsFileSystemArchiveController.java:85)
        at 
de.schlichtherle.truezip.fs.FsFileSystemArchiveController.autoMount(FsFileSystemArchiveController.java:37)
        at 
de.schlichtherle.truezip.fs.FsBasicArchiveController.mknod(FsBasicArchiveController.java:319)
        at 
de.schlichtherle.truezip.fs.FsContextController.mknod(FsContextController.java:178)
        at 
de.schlichtherle.truezip.fs.FsDecoratingController.mknod(FsDecoratingController.java:120)
        at 
de.schlichtherle.truezip.fs.FsCacheController.mknod(FsCacheController.java:157)
        at 
de.schlichtherle.truezip.fs.FsSyncController.mknod(FsSyncController.java:201)
        at 
de.schlichtherle.truezip.fs.FsLockController$1Mknod.call(FsLockController.java:207)
        at 
de.schlichtherle.truezip.fs.FsLockController$1Mknod.call(FsLockController.java:204)
        at 
de.schlichtherle.truezip.fs.FsLockController.locked(FsLockController.java:328)
        at 
de.schlichtherle.truezip.fs.FsLockController.writeLocked(FsLockController.java:268)
        at 
de.schlichtherle.truezip.fs.FsLockController.mknod(FsLockController.java:211)
        at 
de.schlichtherle.truezip.fs.FsDecoratingController.mknod(FsDecoratingController.java:120)
        at 
de.schlichtherle.truezip.fs.FsDecoratingController.mknod(FsDecoratingController.java:120)
        at 
de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Mknod.call(FsFalsePositiveArchiveController.java:431)
        at 
de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Mknod.call(FsFalsePositiveArchiveController.java:426)
        at 
de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$TryChild.call(FsFalsePositiveArchiveController.java:507)
        at 
de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController.call(FsFalsePositiveArchiveController.java:104)
        at 
de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController.mknod(FsFalsePositiveArchiveController.java:436)
        at 
de.schlichtherle.truezip.nio.file.TFileSystem.createDirectory(TFileSystem.java:355)
        ... 4 more
{noformat}

It turns out that this is actually a bug in the NIO.2 implementation of the 
JRE (at least with Oracle JDK 1.7.0_51). The following program reproduces the 
issue:

{code}
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("/"));
    }
}
{code}

When running, this simple program produces:

{noformat}
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)
{noformat}

The exception message is bogus. Of course, my root directory exists. :-) But 
more importantly, the Javadoc for Files.createDirectories(Path, 
FileAttribute<?>...) reads:

{quote}
Unlike the \{@link #createDirectory createDirectory\} method, an exception is 
not thrown if the directory could not be created because it already exists.
{quote}

Of course, I could work around this issue, but creating an archive file in 
the root directory is not a good idea anyway (your permissions may not even 
allow it) and I would not like to issue a new release of TrueZIP and TrueVFS 
just because of a workaround for a broken NIO.2 implementation.

> Exception when creating an archive in the root folder (Windows)
> ---------------------------------------------------------------
>
>                 Key: TRUEZIP-339
>                 URL: https://java.net/jira/browse/TRUEZIP-339
>             Project: TrueZIP
>          Issue Type: Bug
>          Components: TrueZIP Driver FILE
>    Affects Versions: TrueZIP 7.7.5
>         Environment: Windows 7
>            Reporter: qui.tiqe
>            Assignee: Christian Schlichtherle
>            Priority: Minor
>
> When creating an archive in the root folder of a Windows drive (e.g. C:\), 
> TrueZIP throws an exception when using Java 7. The following sample code 
> reproduces the issue:
> {code:title=QTrueZipExportToRoot.java|borderStyle=solid}
> import java.io.BufferedWriter;
> import java.nio.charset.Charset;
> import java.nio.file.Files;
> import java.nio.file.Path;
> import java.nio.file.Paths;
> import de.schlichtherle.truezip.file.TVFS;
> import de.schlichtherle.truezip.nio.file.TPath;
> public class QTrueZipExportToRoot
> {
>   private static final Charset ENCODING = Charset.forName("UTF-8");
>   private static final String ARCHIVE_PATH = "C:\\TestTrueZipRootIssue.zip";
>   
>   public static void main(String[] args)
>   {
>     try
>     {
>       Path archivePath = Paths.get(ARCHIVE_PATH);
>       
>       // Ensure that the file does not already exist
>       if ( Files.exists(archivePath) )
>       {
>         Files.delete(archivePath);
>       }
>             
>       // Create the archive, add a file to it, and write to the file within 
> the archive
>       TPath archiveFile = new TPath(archivePath);
>       Files.createDirectory(archiveFile);
>       TPath newFilePath = archiveFile.resolve("File1");
>       Files.createFile(newFilePath);
>       
>       try ( BufferedWriter writer = Files.newBufferedWriter(newFilePath, 
> ENCODING) )
>       {
>         writer.write("abcd");
>       }
>       
>       // Commit all pending changes
>       TVFS.umount();
>       
>       // Delete the archive if it exists
>       if ( Files.exists( archivePath ) )
>       {
>         Files.delete( archivePath );
>       }
>       
>       System.out.println("Test completed successfully.");
>     }
>     catch (Exception e)
>     {
>       e.printStackTrace();
>     }
>   }
> }
> {code}
> This exception is thrown:
> {noformat}
> java.nio.file.FileAlreadyExistsException: D:\TestTrueZipRootIssue.zip
>       at 
> de.schlichtherle.truezip.nio.file.TFileSystem.createDirectory(TFileSystem.java:362)
>       at 
> de.schlichtherle.truezip.nio.file.TPath.createDirectory(TPath.java:970)
>       at 
> de.schlichtherle.truezip.nio.file.TFileSystemProvider.createDirectory(TFileSystemProvider.java:315)
>       at java.nio.file.Files.createDirectory(Unknown Source)
>       at QTrueZipExportToRoot.main(QTrueZipExportToRoot.java:31)
> Caused by: java.io.IOException: Root directory does not exist
>       at java.nio.file.Files.createDirectories(Unknown Source)
>       at 
> de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.begin(FileOutputSocket.java:109)
>       at 
> de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.newOutputStream(FileOutputSocket.java:222)
>       at 
> de.schlichtherle.truezip.fs.archive.zip.OptionOutputSocket.newOutputStream(OptionOutputSocket.java:48)
>       at 
> de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:586)
>       at 
> de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop0(ZipDriver.java:576)
>       at 
> de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:561)
>       at 
> de.schlichtherle.truezip.fs.FsTargetArchiveController.makeOutputArchive(FsTargetArchiveController.java:247)
>       at 
> de.schlichtherle.truezip.fs.FsTargetArchiveController.mount0(FsTargetArchiveController.java:182)
>       at 
> de.schlichtherle.truezip.fs.FsTargetArchiveController.mount(FsTargetArchiveController.java:155)
>       at 
> de.schlichtherle.truezip.fs.FsFileSystemArchiveController$ResetFileSystem.autoMount(FsFileSystemArchiveController.java:85)
>       at 
> de.schlichtherle.truezip.fs.FsFileSystemArchiveController.autoMount(FsFileSystemArchiveController.java:37)
>       at 
> de.schlichtherle.truezip.fs.FsBasicArchiveController.mknod(FsBasicArchiveController.java:319)
>       at 
> de.schlichtherle.truezip.fs.FsContextController.mknod(FsContextController.java:178)
>       at 
> de.schlichtherle.truezip.fs.FsDecoratingController.mknod(FsDecoratingController.java:120)
>       at 
> de.schlichtherle.truezip.fs.FsCacheController.mknod(FsCacheController.java:157)
>       at 
> de.schlichtherle.truezip.fs.FsSyncController.mknod(FsSyncController.java:201)
>       at 
> de.schlichtherle.truezip.fs.FsLockController$1Mknod.call(FsLockController.java:207)
>       at 
> de.schlichtherle.truezip.fs.FsLockController$1Mknod.call(FsLockController.java:204)
>       at 
> de.schlichtherle.truezip.fs.FsLockController.locked(FsLockController.java:328)
>       at 
> de.schlichtherle.truezip.fs.FsLockController.writeLocked(FsLockController.java:268)
>       at 
> de.schlichtherle.truezip.fs.FsLockController.mknod(FsLockController.java:211)
>       at 
> de.schlichtherle.truezip.fs.FsDecoratingController.mknod(FsDecoratingController.java:120)
>       at 
> de.schlichtherle.truezip.fs.FsDecoratingController.mknod(FsDecoratingController.java:120)
>       at 
> de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Mknod.call(FsFalsePositiveArchiveController.java:431)
>       at 
> de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Mknod.call(FsFalsePositiveArchiveController.java:426)
>       at 
> de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$TryChild.call(FsFalsePositiveArchiveController.java:507)
>       at 
> de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController.call(FsFalsePositiveArchiveController.java:104)
>       at 
> de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController.mknod(FsFalsePositiveArchiveController.java:436)
>       at 
> de.schlichtherle.truezip.nio.file.TFileSystem.createDirectory(TFileSystem.java:355)
>       ... 4 more
> {noformat} 

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://java.net/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


[truezip-issues] [JIRA] Created: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

qui.tiqe (JIRA) 01/16/2014

[truezip-issues] [JIRA] Updated: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

Christian Schlichtherle (JIRA) 01/18/2014

[truezip-issues] [JIRA] Resolved: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

Christian Schlichtherle (JIRA) 01/18/2014

[truezip-issues] [JIRA] Commented: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

qui.tiqe (JIRA) 01/21/2014

[truezip-issues] [JIRA] Reopened: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

Christian Schlichtherle (JIRA) 01/23/2014

[truezip-issues] [JIRA] Updated: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

Christian Schlichtherle (JIRA) 01/23/2014

[truezip-issues] [JIRA] Closed: (TRUEZIP-339) Exception when creating an archive in the root folder (Windows)

Christian Schlichtherle (JIRA) 01/23/2014
 
 
Close
loading
Please Confirm
Close