JDK-6542800 : JarOutputStream Constructor throws ZipException when JarOutputStream is passed as argument
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2007-04-05
  • Updated: 2010-04-02
  • Resolved: 2009-06-10
Related Reports
Relates :  
Description
Description:
    Constructor of java.util.jar.JarOutputStream(OutputStream,Manifest) throws ZipException when JarOutputStream is passed as argument. In other words, wrapping JarOutputStream twice throws ZipException. Please execute the code below to reproduce:

<code>
import java.io.*;
import java.util.jar.*;

public class JarOutputStreamTest {
    public static void main(String...args) throws IOException {
          JarOutputStream jos = new JarOutputStream(new FileOutputStream("new.jar"));
          JarOutputStream jos2 = new JarOutputStream(jos,new Manifest());

    }
}

</code>
<output>
Exception in thread "main" java.util.zip.ZipException: no current ZIP entry
        at java.util.zip.ZipOutputStream.write(ZipOutputStream.java:267)
        at java.util.zip.DeflaterOutputStream.write(DeflaterOutputStream.java:91)
        at java.util.zip.ZipOutputStream.writeInt(ZipOutputStream.java:445)
        at java.util.zip.ZipOutputStream.writeLOC(ZipOutputStream.java:332)
        at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:179)
        at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:90)
        at java.util.jar.JarOutputStream.<init>(JarOutputStream.java:46)
        at JarOutputStreamTest.main(JarOutputStreamTest.java:7)

</output>

Tried in :
<version>
bash-3.00$ java -version
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b10)
Java HotSpot(TM) Client VM (build 1.7.0-ea-b10, mixed mode)

bash-3.00$ uname -a
SunOS hrajan 5.10 Generic sun4u sparc SUNW,Sun-Blade-100
</version>
SQE libs failing testcase: java_util/jar/phase2/JarOutputStreamTest

Comments
EVALUATION This is obvious against the use pattern of Jar/ZipOutputStream, which is to invoke putNextEntry() before write the raw bytes and then closeEntry (optional) after write...the excepton thrown is appropriate in this case.
10-06-2009

EVALUATION The SQE test "JarOutputStreamTest" explicitly tests that a JarOutputStream is not valid as a parameter to the JarOutputStream constructor.
22-10-2007

EVALUATION We do not currently support zip-within-zip, which is essentially what seems to be attempted. At the very least, we should improve the error message.
05-04-2007