harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Svetlana Samoilenko (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-97) ZipOutputStream.close() throws IOException if the stream is already closed
Date Thu, 16 Feb 2006 09:45:59 GMT
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


Mime
View raw message