Apache Lucene open-source search software
remove FSIndexOutput finalizer, move FSIndexInput finalizer to it's Descriptor: LUCENE-750
Yonik Seeley30c8ce4f1043
diff --git a/CHANGES.txt b/CHANGES.txtindex f77c95f5e59..65920ef30ea 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -327,6 +327,10 @@ Optimizationsto the List of clauses and replaced the internal synchronized Vectorwith an unsynchronized List. (Yonik Seeley)+ 16. LUCENE-750: Remove finalizers from FSIndexOutput and move the+ FSIndexInput finalizer to the actual file so all clones don't+ register a new finalizer. (Yonik Seeley)+Test Cases1. Added TestTermScorer.java (Grant Ingersoll)2. Added TestWindowsMMap.java (Benson Margulies via Mike McCandless)diff --git a/src/java/org/apache/lucene/store/FSDirectory.java b/src/java/org/apache/lucene/store/FSDirectory.javaindex 3b40c6125a7..1e4f0ac1614 100644--- a/src/java/org/apache/lucene/store/FSDirectory.java+++ b/src/java/org/apache/lucene/store/FSDirectory.java@@ -496,26 +496,40 @@ public class FSDirectory extends Directory {class FSIndexInput extends BufferedIndexInput {- private class Descriptor extends RandomAccessFile {- public long position;+ private static class Descriptor extends RandomAccessFile {+ // remember if the file is open, so that we don't try to close it+ // more than once+ private boolean isOpen;+ long position;+ final long length;+public Descriptor(File file, String mode) throws IOException {super(file, mode);+ isOpen=true;+ length=length();+ }++ public void close() throws IOException {+ if (isOpen) {+ isOpen=false;+ super.close();+ }+ }++ protected void finalize() throws Throwable {+ try {+ close();+ } finally {+ super.finalize();+ }}}- 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;-+ private final Descriptor file;boolean isClone;- private long length;public FSIndexInput(File path) throws IOException {file = new Descriptor(path, "r");- isOpen = true;- length = file.length();}/** IndexInput methods */@@ -539,27 +553,15 @@ class FSIndexInput extends BufferedIndexInput {}public void close() throws IOException {- // 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;- }+ // only close the file if this is not a clone+ if (!isClone) file.close();}protected void seekInternal(long position) {}public long length() {- return length;- }-- protected void finalize() throws Throwable {- try {- close(); // close the file- } finally {- super.finalize();- }+ return file.length;}public Object clone() {@@ -611,12 +613,4 @@ class FSIndexOutput extends BufferedIndexOutput {return file.length();}- protected void finalize() throws Throwable {- try {- close(); // close the file- } finally {- super.finalize();- }- }-}