From c6f7aa41a35a32312781636ba6bb29d1657d3bb1 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Sun, 22 Mar 2009 13:21:58 +0000 Subject: [PATCH] fix clone() case that could incorrectly leave stored fields files open git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@757185 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/SegmentReader.java | 5 +---- .../lucene/index/TestIndexReaderClone.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/java/org/apache/lucene/index/SegmentReader.java b/src/java/org/apache/lucene/index/SegmentReader.java index acf60b41ac7..721e2b366ec 100644 --- a/src/java/org/apache/lucene/index/SegmentReader.java +++ b/src/java/org/apache/lucene/index/SegmentReader.java @@ -676,10 +676,7 @@ class SegmentReader extends DirectoryIndexReader { clone.freqStream = freqStream; clone.proxStream = proxStream; clone.termVectorsReaderOrig = termVectorsReaderOrig; - - if (fieldsReaderOrig != null) { - clone.fieldsReaderOrig = (FieldsReader) fieldsReaderOrig.clone(); - } + clone.fieldsReaderOrig = fieldsReaderOrig; if (doClone) { if (deletedDocs != null) { diff --git a/src/test/org/apache/lucene/index/TestIndexReaderClone.java b/src/test/org/apache/lucene/index/TestIndexReaderClone.java index f92ba85f1bd..97dbbd3b513 100644 --- a/src/test/org/apache/lucene/index/TestIndexReaderClone.java +++ b/src/test/org/apache/lucene/index/TestIndexReaderClone.java @@ -20,6 +20,8 @@ package org.apache.lucene.index; import org.apache.lucene.index.SegmentReader.Norm; import org.apache.lucene.search.Similarity; import org.apache.lucene.analysis.SimpleAnalyzer; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; import org.apache.lucene.store.Directory; import org.apache.lucene.store.LockObtainFailedException; import org.apache.lucene.store.MockRAMDirectory; @@ -440,4 +442,19 @@ public class TestIndexReaderClone extends LuceneTestCase { r1.close(); dir1.close(); } + + public void testCloseStoredFields() throws Exception { + final Directory dir = new MockRAMDirectory(); + IndexWriter w = new IndexWriter(dir, new SimpleAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED); + w.setUseCompoundFile(false); + Document doc = new Document(); + doc.add(new Field("field", "yes it's stored", Field.Store.YES, Field.Index.ANALYZED)); + w.addDocument(doc); + w.close(); + IndexReader r1 = IndexReader.open(dir); + IndexReader r2 = (IndexReader) r1.clone(false); + r1.close(); + r2.close(); + dir.close(); + } }