Apache Lucene open-source search software
LUCENE-9440: call FieldInfo.checkConsistency for real (not under assert)
Mike McCandlesscb457571e837
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 52a414dd983..4d15969d0b5 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -178,6 +178,9 @@ Improvements* LUCENE-9416: Fix CheckIndex to print an invalid non-zero norm asunsigned long when detecting corruption.+* LUCENE-9440: FieldInfo#checkConsistency called twice from Lucene50(60)FieldInfosFormat#read;+ Removed the (redundant?) assert and do these checks for real. (Yauheni Putsykovich)+Optimizations---------------------diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.javaindex 384dbc2eb65..f8368bc5e14 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java@@ -149,7 +149,6 @@ public final class Lucene50FieldInfosFormat extends FieldInfosFormat {try {infos[i] = new FieldInfo(name, fieldNumber, storeTermVector, omitNorms, storePayloads,indexOptions, docValuesType, dvGen, attributes, 0, 0, 0, false);- infos[i].checkConsistency();} catch (IllegalStateException e) {throw new CorruptIndexException("invalid fieldinfo for field: " + name + ", fieldNumber=" + fieldNumber, input, e);}diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60FieldInfosFormat.javaindex 6ab81cd04db..3b97c267019 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60FieldInfosFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene60/Lucene60FieldInfosFormat.java@@ -165,7 +165,6 @@ public final class Lucene60FieldInfosFormat extends FieldInfosFormat {infos[i] = new FieldInfo(name, fieldNumber, storeTermVector, omitNorms, storePayloads,indexOptions, docValuesType, dvGen, attributes,pointDataDimensionCount, pointIndexDimensionCount, pointNumBytes, isSoftDeletesField);- infos[i].checkConsistency();} catch (IllegalStateException e) {throw new CorruptIndexException("invalid fieldinfo for field: " + name + ", fieldNumber=" + fieldNumber, input, e);}diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfo.javaindex 58b5a66f6bc..b8fe341fc6b 100644--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfo.java@@ -84,7 +84,7 @@ public final class FieldInfo {this.pointIndexDimensionCount = pointIndexDimensionCount;this.pointNumBytes = pointNumBytes;this.softDeletesField = softDeletesField;- assert checkConsistency();+ this.checkConsistency();}/**@@ -179,7 +179,7 @@ public final class FieldInfo {if (attributes != null) {this.attributes.putAll(attributes);}- assert checkConsistency();+ this.checkConsistency();}/** Record that this field is indexed with points, with the@@ -214,7 +214,7 @@ public final class FieldInfo {pointIndexDimensionCount = indexDimensionCount;pointNumBytes = numBytes;- assert checkConsistency();+ this.checkConsistency();}/** Return point data dimension count */@@ -241,7 +241,7 @@ public final class FieldInfo {throw new IllegalArgumentException("cannot change DocValues type from " + docValuesType + " to " + type + " for field \"" + name + "\"");}docValuesType = type;- assert checkConsistency();+ this.checkConsistency();}/** Returns IndexOptions for the field, or IndexOptions.NONE if the field is not indexed */@@ -263,6 +263,7 @@ public final class FieldInfo {// cannot store payloads if we don't store positions:storePayloads = false;}+ this.checkConsistency();}/**@@ -276,7 +277,7 @@ public final class FieldInfo {/** Sets the docValues generation of this field. */void setDocValuesGen(long dvGen) {this.dvGen = dvGen;- assert checkConsistency();+ this.checkConsistency();}/**@@ -289,14 +290,14 @@ public final class FieldInfo {void setStoreTermVectors() {storeTermVector = true;- assert checkConsistency();+ this.checkConsistency();}void setStorePayloads() {if (indexOptions != IndexOptions.NONE && indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0) {storePayloads = true;}- assert checkConsistency();+ this.checkConsistency();}/**@@ -312,6 +313,7 @@ public final class FieldInfo {throw new IllegalStateException("cannot omit norms: this field is not indexed");}omitNorms = true;+ this.checkConsistency();}/**