mirror of https://github.com/apache/lucene.git
LUCENE-7783: Fix NPE when getting points on a non-existing field.
This commit is contained in:
parent
1d74134500
commit
89f6d170f5
|
@ -1217,7 +1217,7 @@ public class MemoryIndex {
|
|||
@Override
|
||||
public PointValues getPointValues(String fieldName) {
|
||||
Info info = fields.get(fieldName);
|
||||
if (info.pointValues == null) {
|
||||
if (info == null || info.pointValues == null) {
|
||||
return null;
|
||||
}
|
||||
return new MemoryIndexPointValues(info);
|
||||
|
@ -1529,6 +1529,7 @@ public class MemoryIndex {
|
|||
|
||||
MemoryIndexPointValues(Info info) {
|
||||
this.info = Objects.requireNonNull(info);
|
||||
Objects.requireNonNull(info.pointValues, "Field does not have points");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1548,12 +1549,7 @@ public class MemoryIndex {
|
|||
|
||||
@Override
|
||||
public byte[] getMinPackedValue() throws IOException {
|
||||
BytesRef[] values = info.pointValues;
|
||||
if (values != null) {
|
||||
return info.minPackedValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return info.minPackedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.apache.lucene.document.NumericDocValuesField;
|
|||
import org.apache.lucene.document.SortedDocValuesField;
|
||||
import org.apache.lucene.document.SortedNumericDocValuesField;
|
||||
import org.apache.lucene.document.SortedSetDocValuesField;
|
||||
import org.apache.lucene.document.StoredField;
|
||||
import org.apache.lucene.document.StringField;
|
||||
import org.apache.lucene.document.TextField;
|
||||
import org.apache.lucene.index.BinaryDocValues;
|
||||
|
@ -422,6 +423,17 @@ public class TestMemoryIndex extends LuceneTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testMissingPoints() throws IOException {
|
||||
Document doc = new Document();
|
||||
doc.add(new StoredField("field", 42));
|
||||
MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer);
|
||||
IndexSearcher indexSearcher = mi.createSearcher();
|
||||
// field that exists but does not have points
|
||||
assertNull(indexSearcher.getIndexReader().leaves().get(0).reader().getPointValues("field"));
|
||||
// field that does not exist
|
||||
assertNull(indexSearcher.getIndexReader().leaves().get(0).reader().getPointValues("some_missing_field"));
|
||||
}
|
||||
|
||||
public void testPointValuesDoNotAffectPositionsOrOffset() throws Exception {
|
||||
MemoryIndex mi = new MemoryIndex(true, true);
|
||||
mi.addField(new TextField("text", "quick brown fox", Field.Store.NO), analyzer);
|
||||
|
|
Loading…
Reference in New Issue