Return-Path: X-Original-To: apmail-db-derby-commits-archive@www.apache.org Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6692BDBF8 for ; Thu, 25 Oct 2012 11:56:28 +0000 (UTC) Received: (qmail 69576 invoked by uid 500); 25 Oct 2012 11:56:28 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 68889 invoked by uid 500); 25 Oct 2012 11:56:23 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 68860 invoked by uid 99); 25 Oct 2012 11:56:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2012 11:56:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 Oct 2012 11:56:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0349A23888E4; Thu, 25 Oct 2012 11:55:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Thu, 25 Oct 2012 11:55:34 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121025115535.0349A23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 * *

* 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); }