diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java index c66e0584dee..ca527725121 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xTermVectorsReader.java @@ -239,7 +239,7 @@ class Lucene3xTermVectorsReader extends TermVectorsReader { @Override public String next() throws IOException { if (fieldNumbers != null && fieldUpto < fieldNumbers.length) { - return fieldInfos.fieldName(fieldNumbers[fieldUpto++]); + return fieldInfos.fieldInfo(fieldNumbers[fieldUpto++]).name; } else { return null; } @@ -247,7 +247,7 @@ class Lucene3xTermVectorsReader extends TermVectorsReader { @Override public Terms terms() throws IOException { - return TVFields.this.terms(fieldInfos.fieldName(fieldNumbers[fieldUpto-1])); + return TVFields.this.terms(fieldInfos.fieldInfo(fieldNumbers[fieldUpto-1]).name); } }; } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/TermBuffer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/TermBuffer.java index 6ce28874b33..90620df508d 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/TermBuffer.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/TermBuffer.java @@ -67,9 +67,15 @@ final class TermBuffer implements Cloneable { final int fieldNumber = input.readVInt(); if (fieldNumber != currentFieldNumber) { currentFieldNumber = fieldNumber; - field = fieldInfos.fieldName(currentFieldNumber).intern(); + // nocommit: too much sneakiness here, seriously this is a negative vint?! + if (currentFieldNumber == -1) { + field = ""; + } else { + assert fieldInfos.fieldInfo(currentFieldNumber) != null : currentFieldNumber; + field = fieldInfos.fieldInfo(currentFieldNumber).name.intern(); + } } else { - assert field.equals(fieldInfos.fieldName(fieldNumber)): "currentFieldNumber=" + currentFieldNumber + " field=" + field + " vs " + fieldInfos.fieldName(fieldNumber); + assert field.equals(fieldInfos.fieldInfo(fieldNumber).name) : "currentFieldNumber=" + currentFieldNumber + " field=" + field + " vs " + fieldInfos.fieldInfo(fieldNumber) == null ? "null" : fieldInfos.fieldInfo(fieldNumber).name; } } diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java index c0420d1ba95..5692fd4d760 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40TermVectorsReader.java @@ -276,7 +276,7 @@ public class Lucene40TermVectorsReader extends TermVectorsReader { @Override public String next() throws IOException { if (fieldNumbers != null && fieldUpto < fieldNumbers.length) { - return fieldInfos.fieldName(fieldNumbers[fieldUpto++]); + return fieldInfos.fieldInfo(fieldNumbers[fieldUpto++]).name; } else { return null; } @@ -284,7 +284,7 @@ public class Lucene40TermVectorsReader extends TermVectorsReader { @Override public Terms terms() throws IOException { - return TVFields.this.terms(fieldInfos.fieldName(fieldNumbers[fieldUpto-1])); + return TVFields.this.terms(fieldInfos.fieldInfo(fieldNumbers[fieldUpto-1]).name); } }; } diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java index f3f8573b245..eb5b7788901 100644 --- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java @@ -338,18 +338,6 @@ public final class FieldInfos implements Iterable { return byName.get(fieldName); } - /** - * Return the fieldName identified by its number. - * - * @param fieldNumber - * @return the fieldName or an empty string when the field - * with the given number doesn't exist. - */ - public String fieldName(int fieldNumber) { - FieldInfo fi = fieldInfo(fieldNumber); - return (fi != null) ? fi.name : ""; - } - /** * Return the fieldinfo object referenced by the fieldNumber. * @param fieldNumber diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java index 316ade37198..d205afdf2e8 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java @@ -150,7 +150,8 @@ final class SegmentMerger { boolean same = true; FieldInfos segmentFieldInfos = segmentReader.getFieldInfos(); for (FieldInfo fi : segmentFieldInfos) { - if (!mergeState.fieldInfos.fieldName(fi.number).equals(fi.name)) { + FieldInfo other = mergeState.fieldInfos.fieldInfo(fi.number); + if (other == null || !other.name.equals(fi.name)) { same = false; break; } diff --git a/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java b/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java index 6dbc43bbe55..83cfa2468b4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestFieldInfos.java @@ -156,7 +156,7 @@ public class TestFieldInfos extends LuceneTestCase { assertEquals(modifiable.size(), readOnly.size()); // assert we can iterate for (FieldInfo fi : readOnly) { - assertEquals(fi.name, modifiable.fieldName(fi.number)); + assertEquals(fi.name, modifiable.fieldInfo(fi.number).name); } } diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java index 89bfa1cfa39..1c68b5be4e1 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java +++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene3x/TermInfosWriter.java @@ -21,6 +21,7 @@ package org.apache.lucene.codecs.lucene3x; import java.io.Closeable; import java.io.IOException; +import org.apache.lucene.index.FieldInfo; import org.apache.lucene.index.FieldInfos; import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.store.Directory; @@ -154,12 +155,18 @@ final class TermInfosWriter implements Closeable { utf16Result2 = new CharsRef(10); return true; } + + // nocommit: temporary hacknuke this. + static String fieldName(FieldInfos infos, int fieldNumber) { + FieldInfo fi = infos.fieldInfo(fieldNumber); + return (fi != null) ? fi.name : ""; + } // Currently used only by assert statement private int compareToLastTerm(int fieldNumber, BytesRef term) { if (lastFieldNumber != fieldNumber) { - final int cmp = fieldInfos.fieldName(lastFieldNumber).compareTo(fieldInfos.fieldName(fieldNumber)); + final int cmp = fieldName(fieldInfos, lastFieldNumber).compareTo(fieldName(fieldInfos, fieldNumber)); // If there is a field named "" (empty string) then we // will get 0 on this comparison, yet, it's "OK". But // it's not OK if two different field numbers map to @@ -203,8 +210,8 @@ final class TermInfosWriter implements Closeable { assert compareToLastTerm(fieldNumber, term) < 0 || (isIndex && term.length == 0 && lastTerm.length == 0) : - "Terms are out of order: field=" + fieldInfos.fieldName(fieldNumber) + " (number " + fieldNumber + ")" + - " lastField=" + fieldInfos.fieldName(lastFieldNumber) + " (number " + lastFieldNumber + ")" + + "Terms are out of order: field=" + fieldName(fieldInfos, fieldNumber) + " (number " + fieldNumber + ")" + + " lastField=" + fieldName(fieldInfos, lastFieldNumber) + " (number " + lastFieldNumber + ")" + " text=" + term.utf8ToString() + " lastText=" + lastTerm.utf8ToString(); assert ti.freqPointer >= lastTi.freqPointer: "freqPointer out of order (" + ti.freqPointer + " < " + lastTi.freqPointer + ")";