harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r378246 - in /incubator/harmony/enhanced/classlib/trunk/modules/archive/src: main/java/java/util/zip/ test/java/org/apache/harmony/tests/java/util/zip/
Date Thu, 16 Feb 2006 13:43:14 GMT
Author: tellison
Date: Thu Feb 16 05:43:12 2006
New Revision: 378246

URL: http://svn.apache.org/viewcvs?rev=378246&view=rev
Log:
Fix for HARMONY-97 (ZipOutputStream.close() throws IOException if the stream is already closed)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipOutputStreamTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
    incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java?rev=378246&r1=378245&r2=378246&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
Thu Feb 16 05:43:12 2006
@@ -71,14 +71,17 @@
 
 	/**
 	 * Closes the current ZipEntry if any. Closes the underlying output stream.
+	 * If the stream is already closed this method does nothing.
 	 * 
 	 * @exception IOException
 	 *                If an error occurs closing the stream
 	 */
 	public void close() throws IOException {
-		finish();
-		out.close();
-		out = null;
+		if (out != null) {
+			finish();
+			out.close();
+			out = null;
+		}
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java?rev=378246&r1=378245&r2=378246&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/AllTests.java
Thu Feb 16 05:43:12 2006
@@ -29,6 +29,7 @@
 				"Test for org.apache.harmony.tests.java.util.zip");
 		//$JUnit-BEGIN$
 		suite.addTestSuite(InflaterTest.class);
+		suite.addTestSuite(ZipOutputStreamTest.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipOutputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipOutputStreamTest.java?rev=378246&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipOutputStreamTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/archive/src/test/java/org/apache/harmony/tests/java/util/zip/ZipOutputStreamTest.java
Thu Feb 16 05:43:12 2006
@@ -0,0 +1,53 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.util.zip;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import junit.framework.TestCase;
+
+public class ZipOutputStreamTest extends TestCase {
+
+	/**
+	 * @tests java.util.zip.ZipOutputStream#close()
+	 */
+	public void test_close() throws IOException {
+		// Regression for HARMONY-97
+		ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
+		zos.putNextEntry(new ZipEntry("myFile"));
+		zos.close();
+		zos.close(); // Should be a no-op
+	}
+	
+	/**
+	 * @tests java.util.zip.ZipOutputStream#finish()
+	 */
+	public void test_finish() throws IOException {
+		ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
+		zos.putNextEntry(new ZipEntry("myFile"));
+		zos.finish();
+		zos.close();
+		try {
+			zos.finish();
+			fail("Assert 0: Expected IOException");
+		} catch (IOException e) {
+			// Expected
+		}
+	}
+}



Mime
View raw message