You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by "Svetlana Samoilenko (JIRA)" <ji...@apache.org> on 2006/02/16 10:45:59 UTC

[jira] Created: (HARMONY-97) ZipOutputStream.close() throws IOException if the stream is already closed

ZipOutputStream.close() throws IOException if the stream is already closed
--------------------------------------------------------------------------

         Key: HARMONY-97
         URL: http://issues.apache.org/jira/browse/HARMONY-97
     Project: Harmony
        Type: Bug
  Components: Classlib  
    Reporter: Svetlana Samoilenko


According to 1.5 specification for сlose() method in interface Closeable:
"Closes this stream and releases any system resources associated with it. 
If the stream is already closed then invoking this method has no effect".

Harmony throws IOException if the stream is already closed.

Code to reproduce: 
import java.io.*;
import java.util.zip.*;
public class test2  { 
     public static void main(String args[]) { 
            ZipOutputStream zos = null; 
            try {       
                 File f=new File("myFile");
                 f.createNewFile(); 
                 f.deleteOnExit(); 
                 FileOutputStream ff=new FileOutputStream(f);
                 BufferedOutputStream b=new BufferedOutputStream(ff);
                 zos=new ZipOutputStream(new BufferedOutputStream(b)); 
                 zos.putNextEntry(new ZipEntry("myFile")); 
            } catch (IOException ee) { 
                 ee.printStackTrace(); 
            }
            try {  
                zos.close(); 
                zos.close(); 
                System.out.println("PASSED"); 
            } catch (IOException ee) { 
                System.out.println("FAILED"); 
                ee.printStackTrace(); 
            }
    } 
}

Steps to Reproduce: 
1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 
2. Compile test2.java using BEA 1.4 javac 
> javac -d . test2.java 
3. Run java using compatible VM (J9) 
> java -showversion test2

Output: 
C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
java version "1.4.2_04" 
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) 
PASSED

C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
(c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. 
FAILED
java.io.IOException: Stream is closed
        at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:157)
        at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:66)
        at test2.main(test2.java:26)

Suggested fix:
Index: trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
===================================================================
--- trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java (revision 378195)
+++ trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java            (working copy)
@@ -77,8 +77,7 @@
             */
            public void close() throws IOException {
                        finish();
-                       out.close();
-                       out = null;
+                      out.close();                   
            }
            /**
@@ -165,9 +164,7 @@
             * @exception IOException
             *                If an error occurs while finishing
             */
-           public void finish() throws IOException {
-                       if (out == null)
-                                  throw new IOException(Msg.getString("K0059"));
+          public void finish() throws IOException {             
                        if (cDir == null)
                                    return;
                        if (entries.size() == 0)

 Suggested junit test case:
------------------------ ZipOutputStreamTest.java ------------------------------------------------- 
import junit.framework.*; 
import java.util.zip.*; 
import java.io.*; 
public class ZipOutputStreamTest extends TestCase { 
    public static void main(String[] args) { 
        junit.textui.TestRunner.run(ZipOutputStream.class); 
    } 
    public void test_close() { 
        ZipOutputStream zos = null; 
        try {       
            File f=new File("myFile");
            f.createNewFile(); 
            f.deleteOnExit(); 
            FileOutputStream ff=new FileOutputStream(f);
            BufferedOutputStream b=new BufferedOutputStream(ff);
            zos=new ZipOutputStream(new BufferedOutputStream(b)); 
            zos.putNextEntry(new ZipEntry("myFile")); 
         } catch (IOException ee) { 
            fail("Unnexpected IOException");
         }
         try {  
             zos.close(); 
             zos.close(); 
         } catch (IOException ee) { 
             fail("Unnexpected IOException");             
         }
    } 
}



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Re: [jira] Created: (HARMONY-97) ZipOutputStream.close() throws IOException if the stream is already closed

Posted by Tim Ellison <t....@gmail.com>.
Svetlana,

Thanks for another great bug report -- keep them coming.

I have two requests:

 - since you are sending a good number of tests and patches that I'm
starting to apply to the harmony code base (and therefore backing them
out is going to be increasingly difficult<g>), please will you complete
an Authorized Contributor Questionnaire to ensure that the work you are
doing can rightfully be accepted.

 - it would make life a bit easier (for me) if you attached the patch as
a file, remembering to flag it as granted to ASF, rather than putting it
in the description.

Thanks again!
Tim


Svetlana Samoilenko (JIRA) wrote:
> ZipOutputStream.close() throws IOException if the stream is already closed
> --------------------------------------------------------------------------
> 
>          Key: HARMONY-97
>          URL: http://issues.apache.org/jira/browse/HARMONY-97
>      Project: Harmony
>         Type: Bug
>   Components: Classlib  
>     Reporter: Svetlana Samoilenko
> 
> 
> According to 1.5 specification for сlose() method in interface Closeable:
> "Closes this stream and releases any system resources associated with it. 
> If the stream is already closed then invoking this method has no effect".
> 
> Harmony throws IOException if the stream is already closed.
> 
> Code to reproduce: 
> import java.io.*;
> import java.util.zip.*;
> public class test2  { 
>      public static void main(String args[]) { 
>             ZipOutputStream zos = null; 
>             try {       
>                  File f=new File("myFile");
>                  f.createNewFile(); 
>                  f.deleteOnExit(); 
>                  FileOutputStream ff=new FileOutputStream(f);
>                  BufferedOutputStream b=new BufferedOutputStream(ff);
>                  zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>                  zos.putNextEntry(new ZipEntry("myFile")); 
>             } catch (IOException ee) { 
>                  ee.printStackTrace(); 
>             }
>             try {  
>                 zos.close(); 
>                 zos.close(); 
>                 System.out.println("PASSED"); 
>             } catch (IOException ee) { 
>                 System.out.println("FAILED"); 
>                 ee.printStackTrace(); 
>             }
>     } 
> }
> 
> Steps to Reproduce: 
> 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 
> 2. Compile test2.java using BEA 1.4 javac 
>> javac -d . test2.java 
> 3. Run java using compatible VM (J9) 
>> java -showversion test2
> 
> Output: 
> C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
> java version "1.4.2_04" 
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) 
> PASSED
> 
> C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. 
> FAILED
> java.io.IOException: Stream is closed
>         at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:157)
>         at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:66)
>         at test2.main(test2.java:26)
> 
> Suggested fix:
> Index: trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
> ===================================================================
> --- trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java (revision 378195)
> +++ trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java            (working copy)
> @@ -77,8 +77,7 @@
>              */
>             public void close() throws IOException {
>                         finish();
> -                       out.close();
> -                       out = null;
> +                      out.close();                   
>             }
>             /**
> @@ -165,9 +164,7 @@
>              * @exception IOException
>              *                If an error occurs while finishing
>              */
> -           public void finish() throws IOException {
> -                       if (out == null)
> -                                  throw new IOException(Msg.getString("K0059"));
> +          public void finish() throws IOException {             
>                         if (cDir == null)
>                                     return;
>                         if (entries.size() == 0)
> 
>  Suggested junit test case:
> ------------------------ ZipOutputStreamTest.java ------------------------------------------------- 
> import junit.framework.*; 
> import java.util.zip.*; 
> import java.io.*; 
> public class ZipOutputStreamTest extends TestCase { 
>     public static void main(String[] args) { 
>         junit.textui.TestRunner.run(ZipOutputStream.class); 
>     } 
>     public void test_close() { 
>         ZipOutputStream zos = null; 
>         try {       
>             File f=new File("myFile");
>             f.createNewFile(); 
>             f.deleteOnExit(); 
>             FileOutputStream ff=new FileOutputStream(f);
>             BufferedOutputStream b=new BufferedOutputStream(ff);
>             zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>             zos.putNextEntry(new ZipEntry("myFile")); 
>          } catch (IOException ee) { 
>             fail("Unnexpected IOException");
>          }
>          try {  
>              zos.close(); 
>              zos.close(); 
>          } catch (IOException ee) { 
>              fail("Unnexpected IOException");             
>          }
>     } 
> }
> 
> 
> 

-- 

Tim Ellison (t.p.ellison@gmail.com)
IBM Java technology centre, UK.

[jira] Commented: (HARMONY-97) ZipOutputStream.close() throws IOException if the stream is already closed

Posted by "Svetlana Samoilenko (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-97?page=comments#action_12366743 ] 

Svetlana Samoilenko commented on HARMONY-97:
--------------------------------------------

Tim, thank you, bug is not reproducible with latest sources.

> ZipOutputStream.close() throws IOException if the stream is already closed
> --------------------------------------------------------------------------
>
>          Key: HARMONY-97
>          URL: http://issues.apache.org/jira/browse/HARMONY-97
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: Svetlana Samoilenko
>     Assignee: Tim Ellison

>
> According to 1.5 specification for ?lose() method in interface Closeable:
> "Closes this stream and releases any system resources associated with it. 
> If the stream is already closed then invoking this method has no effect".
> Harmony throws IOException if the stream is already closed.
> Code to reproduce: 
> import java.io.*;
> import java.util.zip.*;
> public class test2  { 
>      public static void main(String args[]) { 
>             ZipOutputStream zos = null; 
>             try {       
>                  File f=new File("myFile");
>                  f.createNewFile(); 
>                  f.deleteOnExit(); 
>                  FileOutputStream ff=new FileOutputStream(f);
>                  BufferedOutputStream b=new BufferedOutputStream(ff);
>                  zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>                  zos.putNextEntry(new ZipEntry("myFile")); 
>             } catch (IOException ee) { 
>                  ee.printStackTrace(); 
>             }
>             try {  
>                 zos.close(); 
>                 zos.close(); 
>                 System.out.println("PASSED"); 
>             } catch (IOException ee) { 
>                 System.out.println("FAILED"); 
>                 ee.printStackTrace(); 
>             }
>     } 
> }
> Steps to Reproduce: 
> 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 
> 2. Compile test2.java using BEA 1.4 javac 
> > javac -d . test2.java 
> 3. Run java using compatible VM (J9) 
> > java -showversion test2
> Output: 
> C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
> java version "1.4.2_04" 
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) 
> PASSED
> C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. 
> FAILED
> java.io.IOException: Stream is closed
>         at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:157)
>         at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:66)
>         at test2.main(test2.java:26)
> Suggested fix:
> Index: trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
> ===================================================================
> --- trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java (revision 378195)
> +++ trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java            (working copy)
> @@ -77,8 +77,7 @@
>              */
>             public void close() throws IOException {
>                         finish();
> -                       out.close();
> -                       out = null;
> +                      out.close();                   
>             }
>             /**
> @@ -165,9 +164,7 @@
>              * @exception IOException
>              *                If an error occurs while finishing
>              */
> -           public void finish() throws IOException {
> -                       if (out == null)
> -                                  throw new IOException(Msg.getString("K0059"));
> +          public void finish() throws IOException {             
>                         if (cDir == null)
>                                     return;
>                         if (entries.size() == 0)
>  Suggested junit test case:
> ------------------------ ZipOutputStreamTest.java ------------------------------------------------- 
> import junit.framework.*; 
> import java.util.zip.*; 
> import java.io.*; 
> public class ZipOutputStreamTest extends TestCase { 
>     public static void main(String[] args) { 
>         junit.textui.TestRunner.run(ZipOutputStream.class); 
>     } 
>     public void test_close() { 
>         ZipOutputStream zos = null; 
>         try {       
>             File f=new File("myFile");
>             f.createNewFile(); 
>             f.deleteOnExit(); 
>             FileOutputStream ff=new FileOutputStream(f);
>             BufferedOutputStream b=new BufferedOutputStream(ff);
>             zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>             zos.putNextEntry(new ZipEntry("myFile")); 
>          } catch (IOException ee) { 
>             fail("Unnexpected IOException");
>          }
>          try {  
>              zos.close(); 
>              zos.close(); 
>          } catch (IOException ee) { 
>              fail("Unnexpected IOException");             
>          }
>     } 
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (HARMONY-97) ZipOutputStream.close() throws IOException if the stream is already closed

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-97?page=all ]
     
Tim Ellison closed HARMONY-97:
------------------------------


Verified by Svetlana


> ZipOutputStream.close() throws IOException if the stream is already closed
> --------------------------------------------------------------------------
>
>          Key: HARMONY-97
>          URL: http://issues.apache.org/jira/browse/HARMONY-97
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: Svetlana Samoilenko
>     Assignee: Tim Ellison

>
> According to 1.5 specification for ?lose() method in interface Closeable:
> "Closes this stream and releases any system resources associated with it. 
> If the stream is already closed then invoking this method has no effect".
> Harmony throws IOException if the stream is already closed.
> Code to reproduce: 
> import java.io.*;
> import java.util.zip.*;
> public class test2  { 
>      public static void main(String args[]) { 
>             ZipOutputStream zos = null; 
>             try {       
>                  File f=new File("myFile");
>                  f.createNewFile(); 
>                  f.deleteOnExit(); 
>                  FileOutputStream ff=new FileOutputStream(f);
>                  BufferedOutputStream b=new BufferedOutputStream(ff);
>                  zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>                  zos.putNextEntry(new ZipEntry("myFile")); 
>             } catch (IOException ee) { 
>                  ee.printStackTrace(); 
>             }
>             try {  
>                 zos.close(); 
>                 zos.close(); 
>                 System.out.println("PASSED"); 
>             } catch (IOException ee) { 
>                 System.out.println("FAILED"); 
>                 ee.printStackTrace(); 
>             }
>     } 
> }
> Steps to Reproduce: 
> 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 
> 2. Compile test2.java using BEA 1.4 javac 
> > javac -d . test2.java 
> 3. Run java using compatible VM (J9) 
> > java -showversion test2
> Output: 
> C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
> java version "1.4.2_04" 
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) 
> PASSED
> C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. 
> FAILED
> java.io.IOException: Stream is closed
>         at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:157)
>         at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:66)
>         at test2.main(test2.java:26)
> Suggested fix:
> Index: trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
> ===================================================================
> --- trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java (revision 378195)
> +++ trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java            (working copy)
> @@ -77,8 +77,7 @@
>              */
>             public void close() throws IOException {
>                         finish();
> -                       out.close();
> -                       out = null;
> +                      out.close();                   
>             }
>             /**
> @@ -165,9 +164,7 @@
>              * @exception IOException
>              *                If an error occurs while finishing
>              */
> -           public void finish() throws IOException {
> -                       if (out == null)
> -                                  throw new IOException(Msg.getString("K0059"));
> +          public void finish() throws IOException {             
>                         if (cDir == null)
>                                     return;
>                         if (entries.size() == 0)
>  Suggested junit test case:
> ------------------------ ZipOutputStreamTest.java ------------------------------------------------- 
> import junit.framework.*; 
> import java.util.zip.*; 
> import java.io.*; 
> public class ZipOutputStreamTest extends TestCase { 
>     public static void main(String[] args) { 
>         junit.textui.TestRunner.run(ZipOutputStream.class); 
>     } 
>     public void test_close() { 
>         ZipOutputStream zos = null; 
>         try {       
>             File f=new File("myFile");
>             f.createNewFile(); 
>             f.deleteOnExit(); 
>             FileOutputStream ff=new FileOutputStream(f);
>             BufferedOutputStream b=new BufferedOutputStream(ff);
>             zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>             zos.putNextEntry(new ZipEntry("myFile")); 
>          } catch (IOException ee) { 
>             fail("Unnexpected IOException");
>          }
>          try {  
>              zos.close(); 
>              zos.close(); 
>          } catch (IOException ee) { 
>              fail("Unnexpected IOException");             
>          }
>     } 
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Assigned: (HARMONY-97) ZipOutputStream.close() throws IOException if the stream is already closed

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-97?page=all ]

Tim Ellison reassigned HARMONY-97:
----------------------------------

    Assign To: Tim Ellison

> ZipOutputStream.close() throws IOException if the stream is already closed
> --------------------------------------------------------------------------
>
>          Key: HARMONY-97
>          URL: http://issues.apache.org/jira/browse/HARMONY-97
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: Svetlana Samoilenko
>     Assignee: Tim Ellison

>
> According to 1.5 specification for ?lose() method in interface Closeable:
> "Closes this stream and releases any system resources associated with it. 
> If the stream is already closed then invoking this method has no effect".
> Harmony throws IOException if the stream is already closed.
> Code to reproduce: 
> import java.io.*;
> import java.util.zip.*;
> public class test2  { 
>      public static void main(String args[]) { 
>             ZipOutputStream zos = null; 
>             try {       
>                  File f=new File("myFile");
>                  f.createNewFile(); 
>                  f.deleteOnExit(); 
>                  FileOutputStream ff=new FileOutputStream(f);
>                  BufferedOutputStream b=new BufferedOutputStream(ff);
>                  zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>                  zos.putNextEntry(new ZipEntry("myFile")); 
>             } catch (IOException ee) { 
>                  ee.printStackTrace(); 
>             }
>             try {  
>                 zos.close(); 
>                 zos.close(); 
>                 System.out.println("PASSED"); 
>             } catch (IOException ee) { 
>                 System.out.println("FAILED"); 
>                 ee.printStackTrace(); 
>             }
>     } 
> }
> Steps to Reproduce: 
> 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 
> 2. Compile test2.java using BEA 1.4 javac 
> > javac -d . test2.java 
> 3. Run java using compatible VM (J9) 
> > java -showversion test2
> Output: 
> C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
> java version "1.4.2_04" 
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) 
> PASSED
> C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. 
> FAILED
> java.io.IOException: Stream is closed
>         at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:157)
>         at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:66)
>         at test2.main(test2.java:26)
> Suggested fix:
> Index: trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
> ===================================================================
> --- trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java (revision 378195)
> +++ trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java            (working copy)
> @@ -77,8 +77,7 @@
>              */
>             public void close() throws IOException {
>                         finish();
> -                       out.close();
> -                       out = null;
> +                      out.close();                   
>             }
>             /**
> @@ -165,9 +164,7 @@
>              * @exception IOException
>              *                If an error occurs while finishing
>              */
> -           public void finish() throws IOException {
> -                       if (out == null)
> -                                  throw new IOException(Msg.getString("K0059"));
> +          public void finish() throws IOException {             
>                         if (cDir == null)
>                                     return;
>                         if (entries.size() == 0)
>  Suggested junit test case:
> ------------------------ ZipOutputStreamTest.java ------------------------------------------------- 
> import junit.framework.*; 
> import java.util.zip.*; 
> import java.io.*; 
> public class ZipOutputStreamTest extends TestCase { 
>     public static void main(String[] args) { 
>         junit.textui.TestRunner.run(ZipOutputStream.class); 
>     } 
>     public void test_close() { 
>         ZipOutputStream zos = null; 
>         try {       
>             File f=new File("myFile");
>             f.createNewFile(); 
>             f.deleteOnExit(); 
>             FileOutputStream ff=new FileOutputStream(f);
>             BufferedOutputStream b=new BufferedOutputStream(ff);
>             zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>             zos.putNextEntry(new ZipEntry("myFile")); 
>          } catch (IOException ee) { 
>             fail("Unnexpected IOException");
>          }
>          try {  
>              zos.close(); 
>              zos.close(); 
>          } catch (IOException ee) { 
>              fail("Unnexpected IOException");             
>          }
>     } 
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (HARMONY-97) ZipOutputStream.close() throws IOException if the stream is already closed

Posted by "Tim Ellison (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-97?page=all ]
     
Tim Ellison resolved HARMONY-97:
--------------------------------

    Resolution: Fixed

Svetlana,

Fixed in ARCHIVE module java.util.zip.ZipOutputStream at repo revision 378246.
I did not use your patch because it would introduce a regression in finish().

Please check that this fully resolves your problem.


> ZipOutputStream.close() throws IOException if the stream is already closed
> --------------------------------------------------------------------------
>
>          Key: HARMONY-97
>          URL: http://issues.apache.org/jira/browse/HARMONY-97
>      Project: Harmony
>         Type: Bug
>   Components: Classlib
>     Reporter: Svetlana Samoilenko
>     Assignee: Tim Ellison

>
> According to 1.5 specification for ?lose() method in interface Closeable:
> "Closes this stream and releases any system resources associated with it. 
> If the stream is already closed then invoking this method has no effect".
> Harmony throws IOException if the stream is already closed.
> Code to reproduce: 
> import java.io.*;
> import java.util.zip.*;
> public class test2  { 
>      public static void main(String args[]) { 
>             ZipOutputStream zos = null; 
>             try {       
>                  File f=new File("myFile");
>                  f.createNewFile(); 
>                  f.deleteOnExit(); 
>                  FileOutputStream ff=new FileOutputStream(f);
>                  BufferedOutputStream b=new BufferedOutputStream(ff);
>                  zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>                  zos.putNextEntry(new ZipEntry("myFile")); 
>             } catch (IOException ee) { 
>                  ee.printStackTrace(); 
>             }
>             try {  
>                 zos.close(); 
>                 zos.close(); 
>                 System.out.println("PASSED"); 
>             } catch (IOException ee) { 
>                 System.out.println("FAILED"); 
>                 ee.printStackTrace(); 
>             }
>     } 
> }
> Steps to Reproduce: 
> 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in README.txt. 
> 2. Compile test2.java using BEA 1.4 javac 
> > javac -d . test2.java 
> 3. Run java using compatible VM (J9) 
> > java -showversion test2
> Output: 
> C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 
> java version "1.4.2_04" 
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) 
> BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) 
> PASSED
> C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 
> (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. 
> FAILED
> java.io.IOException: Stream is closed
>         at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:157)
>         at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:66)
>         at test2.main(test2.java:26)
> Suggested fix:
> Index: trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
> ===================================================================
> --- trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java (revision 378195)
> +++ trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java            (working copy)
> @@ -77,8 +77,7 @@
>              */
>             public void close() throws IOException {
>                         finish();
> -                       out.close();
> -                       out = null;
> +                      out.close();                   
>             }
>             /**
> @@ -165,9 +164,7 @@
>              * @exception IOException
>              *                If an error occurs while finishing
>              */
> -           public void finish() throws IOException {
> -                       if (out == null)
> -                                  throw new IOException(Msg.getString("K0059"));
> +          public void finish() throws IOException {             
>                         if (cDir == null)
>                                     return;
>                         if (entries.size() == 0)
>  Suggested junit test case:
> ------------------------ ZipOutputStreamTest.java ------------------------------------------------- 
> import junit.framework.*; 
> import java.util.zip.*; 
> import java.io.*; 
> public class ZipOutputStreamTest extends TestCase { 
>     public static void main(String[] args) { 
>         junit.textui.TestRunner.run(ZipOutputStream.class); 
>     } 
>     public void test_close() { 
>         ZipOutputStream zos = null; 
>         try {       
>             File f=new File("myFile");
>             f.createNewFile(); 
>             f.deleteOnExit(); 
>             FileOutputStream ff=new FileOutputStream(f);
>             BufferedOutputStream b=new BufferedOutputStream(ff);
>             zos=new ZipOutputStream(new BufferedOutputStream(b)); 
>             zos.putNextEntry(new ZipEntry("myFile")); 
>          } catch (IOException ee) { 
>             fail("Unnexpected IOException");
>          }
>          try {  
>              zos.close(); 
>              zos.close(); 
>          } catch (IOException ee) { 
>              fail("Unnexpected IOException");             
>          }
>     } 
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira