avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1445427 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
Date Tue, 12 Feb 2013 23:28:11 GMT
Author: cutting
Date: Tue Feb 12 23:28:10 2013
New Revision: 1445427

URL: http://svn.apache.org/r1445427
Log:
AVRO-1249. Java: Fix DataFileWriter#close() to not throw an exception when called twice. 
Contributed by E. Sammer.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1445427&r1=1445426&r2=1445427&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Feb 12 23:28:10 2013
@@ -63,6 +63,9 @@ Trunk (not yet released)
     AVRO-1220. Java: Fix a deadlock when reading by replacing parser
     symbol constructors with factory methods. (cutting)
 
+    AVRO-1249. Java: Fix DataFileWriter#close() to not throw an
+    exception when called twice.  (E. Sammer via cutting)
+
 Avro 1.7.3 (6 December 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java?rev=1445427&r1=1445426&r2=1445427&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/file/DataFileWriter.java Tue Feb
12 23:28:10 2013
@@ -371,9 +371,11 @@ public class DataFileWriter<D> implement
   /** Close the file. */
   @Override
   public void close() throws IOException {
-    flush();
-    out.close();
-    isOpen = false;
+    if (isOpen) {
+      flush();
+      out.close();
+      isOpen = false;
+    }
   }
 
   private class BufferedFileOutputStream extends BufferedOutputStream {

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java?rev=1445427&r1=1445426&r2=1445427&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/TestDataFile.java Tue Feb 12 23:28:10
2013
@@ -126,6 +126,17 @@ public class TestDataFile {
     } finally {
       writer.close();
     }
+
+    // Ensure that a second call to close doesn't raise an exception. (AVRO-1249)
+    Exception doubleCloseEx = null;
+
+    try {
+      writer.close();
+    } catch (Exception e) {
+      doubleCloseEx = e;
+    }
+
+    Assert.assertNull("Double close() threw an unexpected exception", doubleCloseEx);
   }
 
   public void testGenericRead() throws IOException {



Mime
View raw message