mirror of https://github.com/apache/lucene.git
LUCENE-4225: fix NPEs when index doesn't have payloads nor offsets
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/pforcodec_3892@1368664 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b43fd8ab8a
commit
9130567fa6
|
@ -20,6 +20,7 @@ package org.apache.lucene.codecs.block;
|
|||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.lucene.codecs.BlockTermState;
|
||||
import org.apache.lucene.codecs.CodecUtil;
|
||||
|
@ -270,7 +271,10 @@ public final class BlockPostingsReader extends PostingsReaderBase {
|
|||
DocsAndPositionsEnum reuse, int flags)
|
||||
throws IOException {
|
||||
|
||||
if ((flags & DocsAndPositionsEnum.FLAG_OFFSETS) == 0 &&
|
||||
boolean indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
|
||||
boolean indexHasPayloasd = fieldInfo.hasPayloads();
|
||||
|
||||
if ((!indexHasOffsets || (flags & DocsAndPositionsEnum.FLAG_OFFSETS) == 0) &&
|
||||
(!fieldInfo.hasPayloads() || (flags & DocsAndPositionsEnum.FLAG_PAYLOADS) == 0)) {
|
||||
BlockDocsAndPositionsEnum docsAndPositionsEnum;
|
||||
if (reuse instanceof BlockDocsAndPositionsEnum) {
|
||||
|
@ -361,6 +365,9 @@ public final class BlockPostingsReader extends PostingsReaderBase {
|
|||
skipOffset = termState.skipOffset;
|
||||
|
||||
doc = -1;
|
||||
if (!indexHasFreq) {
|
||||
Arrays.fill(freqBuffer, 1);
|
||||
}
|
||||
accum = 0;
|
||||
docUpto = 0;
|
||||
docBufferUpto = blockSize;
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.lucene.codecs.BlockTermState;
|
||||
import org.apache.lucene.codecs.CodecUtil;
|
||||
|
@ -274,7 +275,10 @@ public final class BlockPackedPostingsReader extends PostingsReaderBase {
|
|||
DocsAndPositionsEnum reuse, int flags)
|
||||
throws IOException {
|
||||
|
||||
if ((flags & DocsAndPositionsEnum.FLAG_OFFSETS) == 0 &&
|
||||
boolean indexHasOffsets = fieldInfo.getIndexOptions().compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) >= 0;
|
||||
boolean indexHasPayloasd = fieldInfo.hasPayloads();
|
||||
|
||||
if ((!indexHasOffsets || (flags & DocsAndPositionsEnum.FLAG_OFFSETS) == 0) &&
|
||||
(!fieldInfo.hasPayloads() || (flags & DocsAndPositionsEnum.FLAG_PAYLOADS) == 0)) {
|
||||
BlockDocsAndPositionsEnum docsAndPositionsEnum;
|
||||
if (reuse instanceof BlockDocsAndPositionsEnum) {
|
||||
|
@ -365,6 +369,9 @@ public final class BlockPackedPostingsReader extends PostingsReaderBase {
|
|||
docTermStartFP = termState.docStartFP;
|
||||
docIn.seek(docTermStartFP);
|
||||
skipOffset = termState.skipOffset;
|
||||
if (!indexHasFreq) {
|
||||
Arrays.fill(freqBuffer, 1);
|
||||
}
|
||||
|
||||
doc = -1;
|
||||
accum = 0;
|
||||
|
|
|
@ -908,7 +908,8 @@ public class TestPostingsFormat extends LuceneTestCase {
|
|||
|
||||
// NOTE: you can also test "weaker" index options than
|
||||
// you indexed with:
|
||||
testTerms(fieldsProducer, EnumSet.allOf(Option.class), IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
|
||||
//testTerms(fieldsProducer, EnumSet.allOf(Option.class), IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
|
||||
testTerms(fieldsProducer, EnumSet.complementOf(EnumSet.of(Option.THREADS)), IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
|
||||
|
||||
fieldsProducer.close();
|
||||
dir.close();
|
||||
|
|
Loading…
Reference in New Issue