diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 2d9a1b48a69..28611653987 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -74,6 +74,9 @@ Bug Fixes * LUCENE-4705: Pass on FilterStrategy in FilteredQuery if the filtered query is rewritten. (Simon Willnauer) +* LUCENE-4712: MemoryIndex#normValues() throws NPE if field doesn't exist. + (Simon Willnauer, Ricky Pritchett) + * LUCENE-4550: Shapes wider than 180 degrees would use too much accuracy for the PrefixTree based SpatialStrategy. For a pathological case of nearly 360 degrees and barely any height, it would generate so many indexed terms diff --git a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java index cb40b0d7110..64a9e366185 100644 --- a/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java +++ b/lucene/memory/src/java/org/apache/lucene/index/memory/MemoryIndex.java @@ -1138,7 +1138,8 @@ public class MemoryIndex { @Override public DocValues normValues(String field) { - if (fieldInfos.get(field).omitsNorms()) + FieldInfo fieldInfo = fieldInfos.get(field); + if (fieldInfo == null || fieldInfo.omitsNorms()) return null; DocValues norms = cachedNormValues; Similarity sim = getSimilarity(); diff --git a/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java b/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java index db6a6cce587..cd68341724d 100644 --- a/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java +++ b/lucene/memory/src/test/org/apache/lucene/index/memory/MemoryIndexTest.java @@ -381,6 +381,17 @@ public class MemoryIndexTest extends BaseTokenStreamTestCase { assertTrue("posGap" + mockAnalyzer.getPositionIncrementGap("field") , mindex.search(query) > 0.0001); } + public void testNonExistingsField() throws IOException { + MemoryIndex mindex = new MemoryIndex(random().nextBoolean(), random().nextInt(50) * 1024 * 1024); + MockAnalyzer mockAnalyzer = new MockAnalyzer(random()); + mindex.addField("field", "the quick brown fox", mockAnalyzer); + AtomicReader reader = (AtomicReader) mindex.createSearcher().getIndexReader(); + assertNull(reader.docValues("not-in-index")); + assertNull(reader.normValues("not-in-index")); + assertNull(reader.termDocsEnum(new Term("not-in-index", "foo"))); + assertNull(reader.termPositionsEnum(new Term("not-in-index", "foo"))); + assertNull(reader.terms("not-in-index")); + } public void testDuellMemIndex() throws IOException { LineFileDocs lineFileDocs = new LineFileDocs(random());