Apache Solr open-source search software
LUCENE-6696: Fix FilterDirectoryReader.doClose to call in.close() instead of in.doClose().
Adrien Grand9164f21284a4
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex c3af9c327e4..06335c071a3 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -272,6 +272,9 @@ Bug fixesbut instead throw an exception from setMaxTokenLength() when the givenlength 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 ParallelCompositeReaderdiff --git a/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java b/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.javaindex 6773e6f5fb9..579cde960af 100644--- a/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java+++ b/lucene/core/src/java/org/apache/lucene/index/FilterDirectoryReader.java@@ -131,7 +131,7 @@ public abstract class FilterDirectoryReader extends DirectoryReader {@Overrideprotected void doClose() throws IOException {- in.doClose();+ in.close();}/** Returns the wrapped {@link DirectoryReader}. */diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java b/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.javanew file mode 100644index 00000000000..47578504649--- /dev/null+++ b/lucene/core/src/test/org/apache/lucene/index/TestFilterDirectoryReader.java@@ -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();+ }++}