LUCENE-1301: fix cause of rare NPE in TestIndexWriterExceptions

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@683206 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2008-08-06 09:56:00 +00:00
parent 60b43961da
commit 8d8e83518c
2 changed files with 17 additions and 21 deletions

View File

@ -44,11 +44,11 @@ final class TermsHash extends InvertedDocConsumer {
final int postingsFreeChunk;
final DocumentsWriter docWriter;
TermsHash primaryTermsHash;
private TermsHash primaryTermsHash;
RawPostingList[] postingsFreeList = new RawPostingList[1];
int postingsFreeCount;
int postingsAllocCount;
private RawPostingList[] postingsFreeList = new RawPostingList[1];
private int postingsFreeCount;
private int postingsAllocCount;
boolean trackAllocations;
public TermsHash(final DocumentsWriter docWriter, boolean trackAllocations, final TermsHashConsumer consumer, final TermsHash nextTermsHash) {
@ -176,17 +176,6 @@ final class TermsHash extends InvertedDocConsumer {
return any;
}
// USE ONLY FOR DEBUGGING!
/*
public String getPostingText() {
char[] text = charPool.buffers[p.textStart >> CHAR_BLOCK_SHIFT];
int upto = p.textStart & CHAR_BLOCK_MASK;
while(text[upto] != 0xffff)
upto++;
return new String(text, p.textStart, upto-(p.textStart & BYTE_BLOCK_MASK));
}
*/
synchronized public void recyclePostings(final RawPostingList[] postings, final int numPostings) {
assert postings.length >= numPostings;
@ -219,19 +208,21 @@ final class TermsHash extends InvertedDocConsumer {
postings, 0, numToCopy);
// Directly allocate the remainder if any
if (numToCopy < postings.length) {
if (numToCopy != postings.length) {
final int extra = postings.length - numToCopy;
final int newPostingsAllocCount = postingsAllocCount + extra;
if (newPostingsAllocCount > postingsFreeList.length)
postingsFreeList = new RawPostingList[ArrayUtil.getNextSize(newPostingsAllocCount)];
consumer.createPostings(postings, numToCopy, extra);
assert docWriter.writer.testPoint("TermsHash.getPostings after create");
postingsAllocCount += extra;
if (trackAllocations)
docWriter.bytesAllocated(extra * bytesPerPosting);
if (newPostingsAllocCount > postingsFreeList.length)
// Pre-allocate the postingsFreeList so it's large
// enough to hold all postings we've given out
postingsFreeList = new RawPostingList[ArrayUtil.getNextSize(newPostingsAllocCount)];
}
postingsFreeCount -= numToCopy;

View File

@ -74,8 +74,13 @@ final class TermsHashPerThread extends InvertedDocConsumerPerThread {
assert freePostingsCount == 0;
termsHash.getPostings(freePostings);
freePostingsCount = freePostings.length;
for(int i=0;i<freePostingsCount;i++)
assert freePostings[i] != null;
assert noNullPostings(freePostings, freePostingsCount, "consumer=" + consumer);
}
private static boolean noNullPostings(RawPostingList[] postings, int count, String details) {
for(int i=0;i<count;i++)
assert postings[i] != null: "postings[" + i + "] of " + count + " is null: " + details;
return true;
}
public void startDocument() throws IOException {