Apache Lucene open-source search software
LUCENE-5192: FieldInfos.Builder failed to catch adding field with different DV type under some circumstances
Shai Ererad339f4278c56
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 8c6ea6f8abd..d8df7fcae7e 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -149,6 +149,9 @@ Bug Fixesimplementing end() then be sure it calls super.end(). (Robert Muir,Mike McCandless)+* LUCENE-5192: IndexWriter could allow adding same field name with different+ DocValueTypes under some circumstances. (Shai Erera)+API Changes* LUCENE-5094: Add ramBytesUsed() to MultiDocValues.OrdinalMap.diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.javaindex f8b33f7b221..0ca0882e6d7 100644--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java@@ -288,6 +288,8 @@ public class FieldInfos implements Iterable<FieldInfo> {if (docValues != null) {fi.setDocValuesType(docValues);+ // must also update docValuesType map so it's aware of this field's DocValueType+ globalFieldNumbers.docValuesType.put(name, docValues);}if (!fi.omitsNorms() && normType != null) {diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.javaindex 32af5b2da84..64d0baf1c43 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestDocValuesIndexing.java@@ -26,9 +26,11 @@ import org.apache.lucene.analysis.MockAnalyzer;import org.apache.lucene.document.BinaryDocValuesField;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;+import org.apache.lucene.document.Field.Store;import org.apache.lucene.document.NumericDocValuesField;import org.apache.lucene.document.SortedDocValuesField;import org.apache.lucene.document.SortedSetDocValuesField;+import org.apache.lucene.document.StringField;import org.apache.lucene.document.TextField;import org.apache.lucene.search.FieldCache;import org.apache.lucene.store.Directory;@@ -751,4 +753,30 @@ public class TestDocValuesIndexing extends LuceneTestCase {dir.close();}+ public void testSameFieldNameForPostingAndDocValue() throws Exception {+ // LUCENE-5192: FieldInfos.Builder neglected to update+ // globalFieldNumbers.docValuesType map if the field existed, resulting in+ // potentially adding the same field with different DV types.+ Directory dir = newDirectory();+ IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));+ IndexWriter writer = new IndexWriter(dir, conf);++ Document doc = new Document();+ doc.add(new StringField("f", "mock-value", Store.NO));+ doc.add(new NumericDocValuesField("f", 5));+ writer.addDocument(doc);+ writer.commit();++ doc = new Document();+ doc.add(new BinaryDocValuesField("f", new BytesRef("mock")));+ try {+ writer.addDocument(doc);+ fail("should not have succeeded to add a field with different DV type than what already exists");+ } catch (IllegalArgumentException e) {+ writer.rollback();+ }++ dir.close();+ }+}