From fd7664d92b38bc7b4dc5553dffae228fa1c1b22b Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 5 Jan 2012 20:58:05 +0000 Subject: [PATCH] LUCENE-3628: consolidate exceptional cases and move comment to where it should be git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1227832 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/NormsConsumer.java | 6 +++--- .../lucene/index/NormsConsumerPerField.java | 15 +++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/NormsConsumer.java b/lucene/src/java/org/apache/lucene/index/NormsConsumer.java index 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.java index 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 implem return consumer; } + boolean initialized() { + return consumer != null; + } @Override void abort() {