throw ACE not NPE if you close while maybeReopen runs

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1208525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-11-30 17:14:19 +00:00
parent a1aefefdd9
commit 6f6a6c2b09
2 changed files with 12 additions and 4 deletions

View File

@ -159,7 +159,13 @@ public final class SearcherManager {
try {
// IR.openIfChanged preserves NRT and applyDeletes
// in the newly returned reader:
final IndexReader newReader = IndexReader.openIfChanged(currentSearcher.getIndexReader());
final IndexReader newReader;
final IndexSearcher searcherToReopen = acquire();
try {
newReader = IndexReader.openIfChanged(searcherToReopen.getIndexReader());
} finally {
release(searcherToReopen);
}
if (newReader != null) {
final IndexSearcher newSearcher = new IndexSearcher(newReader, es);
boolean success = false;
@ -246,6 +252,10 @@ public final class SearcherManager {
private synchronized void swapSearcher(IndexSearcher newSearcher) throws IOException {
ensureOpen();
// Don't allow un-closing!
if (currentSearcher == null && newSearcher != null) {
throw new AlreadyClosedException("this SearcherManager is closed");
}
final IndexSearcher oldSearcher = currentSearcher;
currentSearcher = newSearcher;
release(oldSearcher);

View File

@ -237,9 +237,7 @@ public class TestSearcherManager extends ThreadedIndexingAndSearchingTestCase {
});
thread.start();
awaitEnterWarm.await();
for (int i = 0; i < 2; i++) {
searcherManager.close();
}
searcherManager.close();
awaitClose.countDown();
thread.join();
try {