Index: lucene/src/test/org/apache/lucene/index/TestIndexReader.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestIndexReader.java (revision 1045172) +++ lucene/src/test/org/apache/lucene/index/TestIndexReader.java (working copy) @@ -1850,5 +1850,16 @@ } dir.close(); } - + + // LUCENE-2812 + public void testIndexExists() throws Exception { + Directory dir = newDirectory(); + IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())); + writer.addDocument(new Document()); + writer.prepareCommit(); + assertFalse(IndexReader.indexExists(dir)); + writer.close(); + assertTrue(IndexReader.indexExists(dir)); + dir.close(); + } } Index: lucene/src/java/org/apache/lucene/index/IndexReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/IndexReader.java (revision 1045172) +++ lucene/src/java/org/apache/lucene/index/IndexReader.java (working copy) @@ -835,13 +835,17 @@ /** * Returns true if an index exists at the specified directory. - * If the directory does not exist or if there is no index in it. * @param directory the directory to check for an index * @return true if an index exists; false otherwise * @throws IOException if there is a problem with accessing the index */ public static boolean indexExists(Directory directory) throws IOException { - return SegmentInfos.getCurrentSegmentGeneration(directory) != -1; + try { + new SegmentInfos().read(directory); + return true; + } catch (IOException ioe) { + return false; + } } /** Returns the number of documents in this index. */