United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6739892 Improve handling of zip encoding through use of property flag
JDK-6739892 : Improve handling of zip encoding through use of property flag

Details
Type:
Enhancement
Submit Date:
2008-08-21
Status:
Closed
Updated Date:
2010-07-29
Project Name:
JDK
Resolved Date:
2009-05-20
Component:
core-libs
OS:
generic
Sub-Component:
java.util.jar
CPU:
generic
Priority:
P3
Resolution:
Won't Fix
Affected Versions:
1.4.2
Fixed Versions:
7

Related Reports
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Backport:
Relates:
Relates:

Sub Tasks

Description
Dear all,

This RFE / defect is concerning a functionality reported by SAP in their internal issue tracking system. The issue is attached to this report for your analysis and I'm just expecting whether this is a functionality that could be built into the JDK 1.4.2 considering the EOL in Septermber. I'm simply expecting a Go or No-Go evaluation that I could report to SAP. 

Thank you very much.

Here is the snippet from SAP :


There are problems with ZIP handling of files with non-UTF8 encoded
file names.
See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499.

In order to improve the situation without changing existing APIs
SAP has implemented following solution for java.util.zip.ZipInputStream
into SAPJVM 5.1 and suggests that SUN should think about a similar
approach for JDK 1.4.2, because we were faced with customer problems on
this version:

A new System Property called com.sap.jvm.ZipEntry.encoding was added
with the following behavior:

 not set: Reading ZIP files with entries with non-UTF8 chars will fail
          with IllegalArgumentException as before this change, but with

          a useful message pointing to the cause of the problem and
          the new System Property
 "default": If decoding an entry name with UTF8 fails, try the
            platform's default encoding. Reading ZIP files will succeed,
            but filenames might be wrong
 <encoding>: If decoding an entry name with UTF8 fails, try the given
             encoding. If the right encoding is given, reading the ZIP
             file will succeed and entry names will be converted
             correctly. WinRar and WinZip seem to use "Cp437" encoding.

The piece of code looks like this:

 Replace

   ZipEntry e = createZipEntry(getUTF8String(b, 0, len));

 by

   // SAPJVM SS 2008-07-02 implemented workaround to be able to use
   // non-UTF8 encoded zip entry names
   String filename = null;
   try {
       // First try getUTF8String for compatibility
       filename = getUTF8String(b, 0, len);
   }
   catch (IllegalArgumentException e) {
       // UTF8 decoding failed!
       // alternative encoding requested?
       String encoding = System.getProperty("com.sap.jvm.ZipEntry.
encoding");
       if (encoding == null) {
           // no alternative encoding requested, just throw the
           // Exception (for compatibility), but add a message
           IllegalArgumentException ee = new IllegalArgumentException(
                   "zip entry name contained non-utf8 chars, try system
property " +
                   "com.sap.jvm.ZipEntry.encoding");
           ee.setStackTrace(e.getStackTrace());
           throw ee;
       }
       // an alternative encoding is requested
       if (encoding.equalsIgnoreCase("default")) {
           // use platform's default encoding

           filename = new String(b, 0, len);
       }
       else {
           // use the specified encoding
           // (WinZip and WinRar seem to use Cp437 )
           filename = new  String(b, 0, len, encoding);
       }
   }
   ZipEntry e = createZipEntry(filename);

Please check whether you could enter such a solution into JDK 1.4.2.

                                    

Comments
EVALUATION

Will implement changes close to what's been suggested. CCC approval necessary
                                     
2008-11-27
EVALUATION

new APIs have been added in JDK7 to address this particular issue. See#4244499. Closed the 7 MR.
                                     
2009-05-20



Hardware and Software, Engineered to Work Together