JDK-6449882 : ZipExceptions when reusing ZipEntry objects
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 5.0u7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-07-18
  • Updated: 2020-10-03
  • Resolved: 2006-07-18
Related Reports
Duplicate :  
Relates :  
Description
In JDK 1.5.0 Update 7, it is not possible to  use 
ZipOutputStream.putNextEntry(new ZipEntry(ze)), if the object "ze"  has been used in a different Zip stream with different compression  level. If one tries to do this, a java.util.zip.ZipException is 
thrown with message text "invalid entry compressed size (expected 22 but  got 25 bytes)".

One soln that worked is  to use  ZipOutputStream.putNextEntry(new ZipEntry(ze.getName())) instad.  But the ISV would like to know when the original problem will be solved.

The attached  sample program ZipEntryProblem.java  illustrates the problem.

Comments
EVALUATION The described behavior has been in effect since at least JDK 1.3.1. The constructor for ZipEntry(ZipEntry e) states: "Creates a new zip entry with fields taken from the specified zip entry." The fields of a ZipEntry include those of the sizes of the entry's data. Re-using a ZipEntry with a different compression level will, unsurprisingly, compress the data to a different size.
18-07-2006

WORK AROUND Use ZipOutputStream.putNextEntry(new ZipEntry(ze.getName())) instad
18-07-2006