|
28 | 28 |
|
29 | 29 | import org.apache.lucene.index.CorruptIndexException;
|
30 | 30 | import org.apache.lucene.index.DirectoryReader;
|
| 31 | +import org.apache.lucene.index.IndexFormatTooOldException; |
31 | 32 | import org.apache.lucene.search.IndexSearcher;
|
32 | 33 | import org.apache.lucene.search.Query;
|
33 | 34 | import org.apache.lucene.search.TopDocs;
|
@@ -121,10 +122,22 @@ private void checkReadable(String indexPath) throws IOException,
|
121 | 122 | IndexSearcher searcher;
|
122 | 123 | try (Directory luceneDirectory = new NIOFSDirectory(new File(filePath).toPath())) {
|
123 | 124 | try (DirectoryReader luceneDirectoryReader = DirectoryReader.open(luceneDirectory)) {
|
| 125 | + // This code never reached because the index is not |
| 126 | + // readable. |
124 | 127 | searcher = new IndexSearcher(luceneDirectoryReader);
|
125 | 128 | TopDocs hits = searcher.search(luceneQuery, 500);
|
126 |
| - assertTrue(hits.totalHits.value >= 1); |
| 129 | + assertTrue(hits.totalHits != null); |
127 | 130 | }
|
| 131 | + } catch (IndexFormatTooOldException ex) { |
| 132 | + // Lucene 10.x throws this more explicit exception whereas 9.x |
| 133 | + // throws IllegalArgumentException. |
| 134 | + // Note that in |
| 135 | + // org.eclipse.help.internal.search.SearchIndex.SearchIndex(File, |
| 136 | + // String, AnalyzerDescriptor, TocManager, String) |
| 137 | + // it catches all these: |
| 138 | + // catch (IndexFormatTooOldException | IndexNotFoundException | |
| 139 | + // IllegalArgumentException e) |
| 140 | + throw new IllegalArgumentException(ex); |
128 | 141 | }
|
129 | 142 | } else {
|
130 | 143 | fail("Cannot resolve to file protocol");
|
|
0 commit comments