LUCENE-4055: remove empty-string-bug-waiting-to-happen

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1338969 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-05-16 01:16:59 +00:00
parent bfd15f8b10
commit 453f34acd6
7 changed files with 25 additions and 23 deletions

View File

@ -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);
}
};
}

View File

@ -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;
}
}

View File

@ -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);
}
};
}

View File

@ -338,18 +338,6 @@ public final class FieldInfos implements Iterable<FieldInfo> {
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

View File

@ -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;
}

View File

@ -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);
}
}

View File

@ -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 + ")";