LUCENE-2045: fix false FNFE

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@833886 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2009-11-08 15:35:56 +00:00
parent 786eb6ce0d
commit 6ae62295e9
3 changed files with 19 additions and 19 deletions

View File

@ -184,6 +184,10 @@ Bug fixes
char (U+FFFD) during indexing, to prevent silent index corruption.
(Peter Keegan, Mike McCandless)
* LUCENE-2045: Fix silly FileNotFoundException hit if you enable
infoStream on IndexWriter and then add an empty document and commit
(Shai Erera via Mike McCandless)
API Changes
* Un-deprecate search(Weight weight, Filter filter, int n) from

View File

@ -584,7 +584,8 @@ final class DocumentsWriter {
consumer.flush(threads, flushState);
if (infoStream != null) {
final long newSegmentSize = segmentSize(flushState.segmentName);
SegmentInfo si = new SegmentInfo(flushState.segmentName, flushState.numDocs, directory);
final long newSegmentSize = si.sizeInBytes();
String message = " oldRAMSize=" + numBytesUsed +
" newFlushedSize=" + newSegmentSize +
" docs/MB=" + nf.format(numDocsInRAM/(newSegmentSize/1024./1024.)) +
@ -1138,24 +1139,6 @@ final class DocumentsWriter {
NumberFormat nf = NumberFormat.getInstance();
// TODO FI: this is not flexible -- we can't hardwire
// extensions in here:
private long segmentSize(String segmentName) throws IOException {
// Used only when infoStream != null
assert infoStream != null;
long size = directory.fileLength(segmentName + ".tii") +
directory.fileLength(segmentName + ".tis") +
directory.fileLength(segmentName + ".frq") +
directory.fileLength(segmentName + ".prx");
final String normFileName = segmentName + ".nrm";
if (directory.fileExists(normFileName))
size += directory.fileLength(normFileName);
return size;
}
// Coarse estimates used to measure RAM usage of buffered deletes
final static int OBJECT_HEADER_BYTES = 8;
final static int POINTER_NUM_BYTE = Constants.JRE_IS_64BIT ? 8 : 4;

View File

@ -4572,4 +4572,17 @@ public class TestIndexWriter extends LuceneTestCase {
_TestUtil.checkIndex(d);
d.close();
}
public void testNoDocsIndex() throws Throwable {
Directory dir = new MockRAMDirectory();
IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
writer.setUseCompoundFile(false);
ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
writer.setInfoStream(new PrintStream(bos));
writer.addDocument(new Document());
writer.close();
_TestUtil.checkIndex(dir);
dir.close();
}
}