United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6542800 JarOutputStream Constructor throws ZipException when JarOutputStream is passed as argument
6542800 : JarOutputStream Constructor throws ZipException when JarOutputStream is passed as argument

Details
Type:
Bug
Submit Date:
2007-04-05
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2009-06-10
Component:
core-libs
OS:
generic
Sub-Component:
java.util.jar
CPU:
generic
Priority:
P4
Resolution:
Not an Issue
Affected Versions:
7
Fixed Versions:

Related Reports
Relates:

Sub Tasks

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.
                                     
2009-06-10
EVALUATION

The SQE test "JarOutputStreamTest" explicitly tests that a JarOutputStream is not valid as a parameter to the JarOutputStream constructor.
                                     
2007-10-22
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.
                                     
2007-04-05



Hardware and Software, Engineered to Work Together