JDK-8014852 : (zipfs) ZipFileSystemProvider: newFileSystem URI format issue
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7,7u21
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2013-05-17
  • Updated: 2013-05-18
  • Resolved: 2013-05-18
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_21 " 
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
(Windows 7 Enterprise 64-bit)

A DESCRIPTION OF THE PROBLEM :
The following statements:

    URI uri = new URI( " jar:file:/C:/Program%20Files/Java/jdk1.7.0_21/lib/ant-javafx.jar " );
    FileSystem newFileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap());

result in an exception (note:  " Program%20Files "  has been changed to  " Program Files "  by ZipFileSystemProvider)

java.lang.IllegalArgumentException: Illegal character in path at index 16: file:/C:/Program Files/Java/jdk1.7.0_21/lib/ant-javafx.jar
at com.sun.nio.zipfs.ZipFileSystemProvider.uriToPath(ZipFileSystemProvider.java:87)
at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:107)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:322)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:272)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to create a ZipFileSystem for a jar/zip which has spaces in the path:

 URI uri = new URI( " jar:file:/C:/Program%20Files/Java/jdk1.7.0_21/lib/ant-javafx.jar " );
    FileSystem newFileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap());

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A FileSystem object should be returned.

No Exceptions.
ACTUAL -
 " Program%20Files "  has been changed to  " Program Files "  by ZipFileSystemProvider resulting in an exception.

java.lang.IllegalArgumentException: Illegal character in path at index 16: file:/C:/Program Files/Java/jdk1.7.0_21/lib/ant-javafx.jar
at com.sun.nio.zipfs.ZipFileSystemProvider.uriToPath(ZipFileSystemProvider.java:87)
at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:107)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:322)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:272)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: Illegal character in path at index 16: file:/C:/Program Files/Java/jdk1.7.0_21/lib/ant-javafx.jar
at com.sun.nio.zipfs.ZipFileSystemProvider.uriToPath(ZipFileSystemProvider.java:87)
at com.sun.nio.zipfs.ZipFileSystemProvider.newFileSystem(ZipFileSystemProvider.java:107)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:322)
at java.nio.file.FileSystems.newFileSystem(FileSystems.java:272)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Make sure you installed Java SE 7 (u21) to the following directory:  " C:/Program Files/Java/jdk1.7.0_21 " 

public class ZipFileProviderTest {

    @Test
    public void testUriToPath() throws URISyntaxException, IOException {
        URI uri = new URI( " jar:file:/C:/Program%20Files/Java/jdk1.7.0_21/lib/ant-javafx.jar " );
        FileSystem newFileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap());
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Unfortunatly, I haven't found a work-around. This is a blocker!

But I think there is an easy fix. Assuming this is the source code:
http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/05c9c157ec51/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystemProvider.java

(though the stack traces mentions line 87 not line 76???)

then in the uriToPath-method (see stack trace) replace:

String spec = uri.getSchemeSpecificPart();

with

String spec = uri.getRawSchemeSpecificPart();
Comments
This is fixed via JDK-7156873 in jdk8, also in the upcoming 7u40.
18-05-2013