LUCENE-8200: Fix NPE in TestIndexWriter

This commit is contained in:
Simon Willnauer 2018-03-14 17:26:06 +01:00
parent 446d38474e
commit b7793372a9
1 changed files with 7 additions and 2 deletions

View File

@ -3100,6 +3100,7 @@ public class TestIndexWriter extends LuceneTestCase {
oldReader = reader;
reader = DirectoryReader.openIfChanged(reader, writer);
assertNotSame(reader, oldReader);
assertNotNull(reader);
oldReader.close();
searcher = new IndexSearcher(reader);
topDocs = searcher.search(new TermQuery(new Term("id", "1")), 10);
@ -3202,8 +3203,12 @@ public class TestIndexWriter extends LuceneTestCase {
writer.forceMerge(1);
DirectoryReader oldReader = reader;
reader = DirectoryReader.openIfChanged(reader, writer);
assertNotSame(oldReader, reader);
if (reader != null) {
oldReader.close();
assertNotSame(oldReader, reader);
} else {
reader = oldReader;
}
for (String id : ids) {
if (updateSeveralDocs) {
assertEquals(2, reader.docFreq(new Term("id", id)));