Skip to content

Apache Lucene open-source search software

LUCENE-5969: assert -> check

Robert Muir98e9122375c7
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.java
index 18fb60984e0..3f6c4014a9c 100755
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50FieldInfosFormat.java
@@ -25,7 +25,6 @@ import org.apache.lucene.codecs.FieldInfosFormat;
import org.apache.lucene.codecs.FieldInfosReader;
import org.apache.lucene.codecs.FieldInfosWriter;
import org.apache.lucene.index.FieldInfo.DocValuesType;
-import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.store.DataOutput;
/**
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.java
index ddd78d0027b..3d6b3de82ba 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.java
@@ -156,16 +156,24 @@ public abstract class PerFieldPostingsFormat extends PostingsFormat {
formatToGroups.put(format, group);
} else {
// we've already seen this format, so just grab its suffix
- assert suffixes.containsKey(formatName);
+ if (!suffixes.containsKey(formatName)) {
+ throw new IllegalStateException("no suffix for format name: " + formatName + ", expected: " + group.suffix);
+ }
}
group.fields.add(field);
String previousValue = fieldInfo.putAttribute(PER_FIELD_FORMAT_KEY, formatName);
- assert previousValue == null;
+ if (previousValue != null) {
+ throw new IllegalStateException("found existing value for " + PER_FIELD_FORMAT_KEY +
+ ", field=" + fieldInfo.name + ", old=" + previousValue + ", new=" + formatName);
+ }
previousValue = fieldInfo.putAttribute(PER_FIELD_SUFFIX_KEY, Integer.toString(group.suffix));
- assert previousValue == null;
+ if (previousValue != null) {
+ throw new IllegalStateException("found existing value for " + PER_FIELD_SUFFIX_KEY +
+ ", field=" + fieldInfo.name + ", old=" + previousValue + ", new=" + group.suffix);
+ }
}
// Second pass: write postings
@@ -221,7 +229,9 @@ public abstract class PerFieldPostingsFormat extends PostingsFormat {
if (formatName != null) {
// null formatName means the field is in fieldInfos, but has no postings!
final String suffix = fi.getAttribute(PER_FIELD_SUFFIX_KEY);
- assert suffix != null;
+ if (suffix == null) {
+ throw new IllegalStateException("missing attribute: " + PER_FIELD_SUFFIX_KEY + " for field: " + fieldName);
+ }
PostingsFormat format = PostingsFormat.forName(formatName);
String segmentSuffix = getSuffix(formatName, suffix);
if (!formats.containsKey(segmentSuffix)) {