Apache Lucene open-source search software
LUCENE-3628: consolidate exceptional cases and move comment to where it should be
Robert Muirfd7664d92b38
diff --git a/lucene/src/java/org/apache/lucene/index/NormsConsumer.java b/lucene/src/java/org/apache/lucene/index/NormsConsumer.javaindex 3e68e04c838..e6e2f6454a2 100644--- a/lucene/src/java/org/apache/lucene/index/NormsConsumer.java+++ b/lucene/src/java/org/apache/lucene/index/NormsConsumer.java@@ -66,14 +66,14 @@ final class NormsConsumer extends InvertedDocEndConsumer {if (state.fieldInfos.hasNorms()) {for (FieldInfo fi : state.fieldInfos) {final NormsConsumerPerField toWrite = (NormsConsumerPerField) fieldsToFlush.get(fi);+ // we must check the final value of omitNorms for the fieldinfo, it could have+ // changed for this field since the first time we added it.if (!fi.omitNorms) {- if (toWrite != null) {+ if (toWrite != null && toWrite.initialized()) {anythingFlushed = true;toWrite.flush(state.numDocs);} else if (fi.isIndexed) {anythingFlushed = true;- // we must check the final value of omitNorms for the fieldinfo, it could have- // changed for this field since the first time we added it.final DocValuesConsumer valuesConsumer = newConsumer(new PerDocWriteState(state), fi);final DocValuesField value = new DocValuesField("");value.setBytes(new BytesRef(new byte[] {0x00}), Type.BYTES_FIXED_STRAIGHT);diff --git a/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java b/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.javaindex ef9d1e77a24..09390372f78 100644--- a/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java+++ b/lucene/src/java/org/apache/lucene/index/NormsConsumerPerField.java@@ -60,16 +60,8 @@ public class NormsConsumerPerField extends InvertedDocEndConsumerPerField implem}void flush(int docCount) throws IOException {- DocValuesConsumer consumer = this.consumer;- if (consumer == null && fieldInfo.isIndexed) {- consumer = getConsumer();- spare.bytes[0] = 0x00;- value.setBytes(spare, Type.BYTES_FIXED_STRAIGHT);- consumer.add(docCount-1, value);- }- if (consumer != null) {- consumer.finish(docCount);- }+ assert initialized();+ consumer.finish(docCount);}private DocValuesConsumer getConsumer() throws IOException {@@ -79,6 +71,9 @@ public class NormsConsumerPerField extends InvertedDocEndConsumerPerField implemreturn consumer;}+ boolean initialized() {+ return consumer != null;+ }@Overridevoid abort() {