JDK-8061777 : (zipfs) IllegalArgumentException in ZipCoder.toString when using Shitft_JIS
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7u72,8u25
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2014-10-15
  • Updated: 2021-03-01
  • Resolved: 2016-06-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9 Other
8u291Fixed 9 b122Fixed openjdk8u292Fixed
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
1.7.0_72
1.8.0_25

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows Version 6.1.7601

EXTRA RELEVANT SYSTEM CONFIGURATION :
Windows System Locale : Japanese

A DESCRIPTION OF THE PROBLEM :
I'm writing a zip utility program with reference to Java SE 7 Documentation.

http://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html

IllegalArgumentException occurs when I try to convert some characters encoding into Shift_JIS.
Some characters are "\u8868" (0x955c in Shift_JIS), "\u7533 " (0x905c in Shift_JIS),  "\u80fd" (0x945c in Shift_JIS) and so on. All the characters have "0x5c".
I have no problem without "0x5c" charcter.

----------
  FileSystem zipfs = FileSystems.newFileSystem(uri, env);
  zipfs.getPath(...);

  Exception in thread "main" java.lang.IllegalArgumentException: MALFORMED[1]
        at com.sun.nio.zipfs.ZipCoder.toString(ZipCoder.java:70)
----------

The encoding of the source code is Shift_JIS, and I compile with "-encoding Shift_JIS" option.

How may I convert this to Shift_JIS filename?


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.IllegalArgumentException: MALFORMED[1]
        at com.sun.nio.zipfs.ZipCoder.toString(ZipCoder.java:70)
        at com.sun.nio.zipfs.ZipCoder.toString(ZipCoder.java:78)
        at com.sun.nio.zipfs.ZipFileSystem.getString(ZipFileSystem.java:916)
        at com.sun.nio.zipfs.ZipFileSystem.deleteFile(ZipFileSystem.java:1342)
        at com.sun.nio.zipfs.ZipPath.delete(ZipPath.java:655)
        at com.sun.nio.zipfs.ZipFileSystemProvider.delete(ZipFileSystemProvider.java:206)
        at java.nio.file.spi.FileSystemProvider.deleteIfExists(Unknown Source)
        at java.nio.file.Files.deleteIfExists(Unknown Source)
        at java.nio.file.CopyMoveHelper.copyToForeignTarget(Unknown Source)
        at java.nio.file.Files.copy(Unknown Source)
        at ZipFSPUser.main(ZipFSPUser.java:20)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class ZipFSPUser {
  public static void main(String [] args) throws Throwable {
    Map<String, String> env = new HashMap<>();
    env.put("create", "true");
    env.put("encoding", "Shift_JIS");
    // locate file system by using the syntax
    // defined in java.net.JarURLConnection
    URI uri = URI.create("jar:file:/C:/codeSamples/zipfs/zipfstest.zip");

    try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
      Path externalTxtFile = Paths.get("C:\\���.txt");
      System.out.println(externalTxtFile);
      Path pathInZipfile = zipfs.getPath("/���.txt");
      // copy a file into the zip file
      Files.copy( externalTxtFile, pathInZipfile, StandardCopyOption.REPLACE_EXISTING );
    }
  }
}

---------- END SOURCE ----------


Comments
code review thread : http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-May/041520.html
31-05-2016

Changed the system locale to japanese language and confirmed this issue with 7u67 as well as 8u40.
22-10-2014