lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r480785 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/store/FSDirectory.java
Date Thu, 30 Nov 2006 00:07:48 GMT
Author: mikemccand
Date: Wed Nov 29 16:07:46 2006
New Revision: 480785

URL: http://svn.apache.org/viewvc?view=rev&rev=480785
Log:
LUCENE-669: don't double-close RandomAccessFile in finalize

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=480785&r1=480784&r2=480785
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed Nov 29 16:07:46 2006
@@ -230,6 +230,12 @@
     classes from contrib/similarity, as their new home is under
     contrib/queries.
 
+25. LUCENE-669: Do not double-close the RandomAccessFile in
+    FSIndexInput/Output during finalize().  Besides sending an
+    IOException up to the GC, this may also be the cause intermittent
+    "The handle is invalid" IOExceptions on Windows when trying to
+    close readers or writers.
+
 Optimizations
 
   1. LUCENE-586: TermDocs.skipTo() is now more efficient for

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?view=diff&rev=480785&r1=480784&r2=480785
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Wed Nov 29 16:07:46
2006
@@ -504,11 +504,17 @@
   }
 
   private Descriptor file = null;
+  
+  // remember if the file is open, so that we don't try to close it
+  // more than once
+  private boolean isOpen;       
+  
   boolean isClone;
   private long length;
 
   public FSIndexInput(File path) throws IOException {
     file = new Descriptor(path, "r");
+    isOpen = true;
     length = file.length();
   }
 
@@ -533,8 +539,12 @@
   }
 
   public void close() throws IOException {
-    if (!isClone)
+    // only close the file if this is not a clone and the
+    // file has not been closed yet
+    if (!isClone && isOpen) {
       file.close();
+      isOpen = false;
+    }
   }
 
   protected void seekInternal(long position) {
@@ -566,8 +576,13 @@
 class FSIndexOutput extends BufferedIndexOutput {
   RandomAccessFile file = null;
 
+  // remember if the file is open, so that we don't try to close it
+  // more than once
+  private boolean isOpen;
+
   public FSIndexOutput(File path) throws IOException {
     file = new RandomAccessFile(path, "rw");
+    isOpen = true;
   }
 
   /** output methods: */
@@ -575,8 +590,12 @@
     file.write(b, 0, size);
   }
   public void close() throws IOException {
-    super.close();
-    file.close();
+    // only close the file if it has not been closed yet
+    if (isOpen) {
+      super.close();
+      file.close();
+      isOpen = false;
+    }
   }
 
   /** Random-access methods */
@@ -589,7 +608,7 @@
   }
 
   protected void finalize() throws IOException {
-    file.close();          // close the file
+    close();          // close the file
   }
 
 }



Mime
View raw message