You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/07/24 15:21:10 UTC

svn commit: r1692505 - in /lucene/dev/trunk/lucene: CHANGES.txt core/src/java/org/apache/lucene/index/FilterDirectoryReader.java core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java

Author: jpountz
Date: Fri Jul 24 13:21:10 2015
New Revision: 1692505

URL: http://svn.apache.org/r1692505
Log:
LUCENE-6696: Fix FilterDirectoryReader.doClose to call in.close() instead of in.doClose().

Added:
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java   (with props)
Modified:
    lucene/dev/trunk/lucene/CHANGES.txt
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java

Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1692505&r1=1692504&r2=1692505&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Fri Jul 24 13:21:10 2015
@@ -272,6 +272,9 @@ Bug fixes
   but instead throw an exception from setMaxTokenLength() when the given
   length is greater than 1M chars.  (Piotr Idzikowski, Steve Rowe)
 
+* LUCENE-6696: Fix FilterDirectoryReader.close() to never close the
+  underlying reader several times. (Adrien Grand)
+
 Changes in Runtime Behavior
 
 * LUCENE-6501: The subreader structure in ParallelCompositeReader

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java?rev=1692505&r1=1692504&r2=1692505&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java Fri Jul 24 13:21:10 2015
@@ -131,7 +131,7 @@ public abstract class FilterDirectoryRea
 
   @Override
   protected void doClose() throws IOException {
-    in.doClose();
+    in.close();
   }
 
   /** Returns the wrapped {@link DirectoryReader}. */

Added: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java?rev=1692505&view=auto
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java (added)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java Fri Jul 24 13:21:10 2015
@@ -0,0 +1,74 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.index.FilterDirectoryReader.SubReaderWrapper;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestFilterDirectoryReader extends LuceneTestCase {
+
+  private static class DummySubReaderWrapper extends SubReaderWrapper {
+
+    @Override
+    public LeafReader wrap(LeafReader reader) {
+      return reader;
+    }
+    
+  }
+
+  private static class DummyFilterDirectoryReader extends FilterDirectoryReader {
+
+    public DummyFilterDirectoryReader(DirectoryReader in) throws IOException {
+      super(in, new DummySubReaderWrapper());
+    }
+
+    @Override
+    protected DirectoryReader doWrapDirectoryReader(DirectoryReader in) throws IOException {
+      return new DummyFilterDirectoryReader(in);
+    }
+    
+  }
+
+  public void testDoubleClose() throws IOException {
+    Directory dir = newDirectory();
+    IndexWriter w = new IndexWriter(dir, newIndexWriterConfig());
+    w.addDocument(new Document());
+
+    DirectoryReader reader = DirectoryReader.open(w, false);
+    DirectoryReader wrapped = new DummyFilterDirectoryReader(reader);
+
+    // Calling close() on the original reader and wrapped reader should only close
+    // the original reader once (as per Closeable.close() contract that close() is
+    // idempotent)
+    List<DirectoryReader> readers = Arrays.asList(reader, wrapped);
+    Collections.shuffle(readers);
+    IOUtils.close(readers);
+
+    w.close();
+    dir.close();
+  }
+
+}