JDK-6739892 : Improve handling of zip encoding through use of property flag
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2008-08-21
  • Updated: 2017-05-19
  • Resolved: 2009-05-20
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.
Other Other Other Other JDK 6
1.4.2_21-revFixed 1.4.2_22-revFixed 1.4.2_23Fixed 5.0u23Fixed 6u17-revFixed
Related Reports
Relates :  
Relates :  
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 new APIs have been added in JDK7 to address this particular issue. See#4244499. Closed the 7 MR.
20-05-2009

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