You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2012/10/25 13:55:34 UTC

svn commit: r1402111 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/io/vfmem/VirtualFile.java engine/org/apache/derby/impl/io/vfmem/VirtualRandomAccessFile.java testing/org/apache/derbyTesting/unitTests/junit/VirtualFileTest.java

Author: kahatlen
Date: Thu Oct 25 11:55:34 2012
New Revision: 1402111

URL: http://svn.apache.org/viewvc?rev=1402111&view=rev
Log:
DERBY-5960: VirtualRandomAccessFile.close() is not idempotent

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualFile.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualRandomAccessFile.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/VirtualFileTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualFile.java?rev=1402111&r1=1402110&r2=1402111&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualFile.java Thu Oct 25 11:55:34 2012
@@ -41,7 +41,7 @@ import org.apache.derby.io.StorageRandom
  * </ul>
  * <p>
  * When a method that requires access to the file data or to know if the file
- * exists or not, the assoicated data store is consulted.
+ * exists or not, the associated data store is consulted.
  */
 public class VirtualFile
         implements StorageFile {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualRandomAccessFile.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualRandomAccessFile.java?rev=1402111&r1=1402110&r2=1402111&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualRandomAccessFile.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/vfmem/VirtualRandomAccessFile.java Thu Oct 25 11:55:34 2012
@@ -25,7 +25,6 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-
 import org.apache.derby.io.StorageRandomAccessFile;
 
 /**
@@ -43,19 +42,19 @@ public class VirtualRandomAccessFile
     /** Current position / file pointer. */
     private long fp;
     /** Stream used to read from the source entry. */
-    private BlockedByteArrayInputStream bIn;
+    private final BlockedByteArrayInputStream bIn;
     /** Data input stream on top of the source input stream. */
-    private DataInputStream dIs;
+    private final DataInputStream dIs;
     /**
      * Stream used to write into the source entry. Will be {@code null} if the
      * file is opened in read-only mode.
      */
-    private BlockedByteArrayOutputStream bOut;
+    private final BlockedByteArrayOutputStream bOut;
     /**
      * Data output stream on top of the source output stream. Will be
      * {@code null} if the file is opened in read-only mode.
      */
-    private DataOutputStream dOs;
+    private final DataOutputStream dOs;
 
     /**
      * Creates a new virtual random access file.
@@ -85,11 +84,9 @@ public class VirtualRandomAccessFile
 
     public void close() throws IOException {
         dIs.close();
-        dIs = null;
         // If opened in read-only mode, the output streams are null.
         if (dOs != null) {
             dOs.close();
-            dOs = null;
         }
         fp = Long.MIN_VALUE;
     }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/VirtualFileTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/VirtualFileTest.java?rev=1402111&r1=1402110&r2=1402111&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/VirtualFileTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/VirtualFileTest.java Thu Oct 25 11:55:34 2012
@@ -336,6 +336,19 @@ public class VirtualFileTest
         assertTrue(vf.isDirectory());
     }
 
+    /**
+     * Verify that the close() method of VirtualRandomAccessFile can be
+     * called more than once.
+     */
+    public void testCloseIdempotent() throws IOException {
+        DataStore store = getStore();
+        VirtualFile f = new VirtualFile("afile", store);
+        StorageRandomAccessFile raf = f.getRandomAccessFile("rw");
+        raf.close();
+        // The second close() used to throw NullPointerException (DERBY-5960)
+        raf.close();
+    }
+
     public static Test suite() {
         return new TestSuite(VirtualFileTest.class);
     }