mirror of https://github.com/apache/lucene.git
LUCENE-5616: remove FieldInfos leniency
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1588507 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b9a22bb5db
commit
8e3727bb05
|
@ -148,6 +148,13 @@ class Lucene42DocValuesProducer extends DocValuesProducer {
|
|||
private void readFields(IndexInput meta, FieldInfos infos) throws IOException {
|
||||
int fieldNumber = meta.readVInt();
|
||||
while (fieldNumber != -1) {
|
||||
// check should be: infos.fieldInfo(fieldNumber) != null, which incorporates negative check
|
||||
// but docvalues updates are currently buggy here (loading extra stuff, etc): LUCENE-5616
|
||||
if (fieldNumber < 0) {
|
||||
// trickier to validate more: because we re-use for norms, because we use multiple entries
|
||||
// for "composite" types like sortedset, etc.
|
||||
throw new CorruptIndexException("Invalid field number: " + fieldNumber + ", input=" + meta);
|
||||
}
|
||||
int fieldType = meta.readByte();
|
||||
if (fieldType == NUMBER) {
|
||||
NumericEntry entry = new NumericEntry();
|
||||
|
|
|
@ -185,6 +185,13 @@ public class Lucene45DocValuesProducer extends DocValuesProducer implements Clos
|
|||
private void readFields(IndexInput meta, FieldInfos infos) throws IOException {
|
||||
int fieldNumber = meta.readVInt();
|
||||
while (fieldNumber != -1) {
|
||||
// check should be: infos.fieldInfo(fieldNumber) != null, which incorporates negative check
|
||||
// but docvalues updates are currently buggy here (loading extra stuff, etc): LUCENE-5616
|
||||
if (fieldNumber < 0) {
|
||||
// trickier to validate more: because we re-use for norms, because we use multiple entries
|
||||
// for "composite" types like sortedset, etc.
|
||||
throw new CorruptIndexException("Invalid field number: " + fieldNumber + " (resource=" + meta + ")");
|
||||
}
|
||||
byte type = meta.readByte();
|
||||
if (type == Lucene45DocValuesFormat.NUMERIC) {
|
||||
numerics.put(fieldNumber, readNumericEntry(meta));
|
||||
|
|
|
@ -58,6 +58,9 @@ public class FieldInfos implements Iterable<FieldInfo> {
|
|||
boolean hasDocValues = false;
|
||||
|
||||
for (FieldInfo info : infos) {
|
||||
if (info.number < 0) {
|
||||
throw new IllegalArgumentException("illegal field number: " + info.number + " for field " + info.name);
|
||||
}
|
||||
FieldInfo previous = byNumber.put(info.number, info);
|
||||
if (previous != null) {
|
||||
throw new IllegalArgumentException("duplicate field numbers: " + previous.name + " and " + info.name + " have: " + info.number);
|
||||
|
@ -148,15 +151,16 @@ public class FieldInfos implements Iterable<FieldInfo> {
|
|||
|
||||
/**
|
||||
* Return the fieldinfo object referenced by the fieldNumber.
|
||||
* @param fieldNumber field's number. if this is negative, this method
|
||||
* always returns null.
|
||||
* @param fieldNumber field's number.
|
||||
* @return the FieldInfo object or null when the given fieldNumber
|
||||
* doesn't exist.
|
||||
*/
|
||||
// TODO: fix this negative behavior, this was something related to Lucene3x?
|
||||
// if the field name is empty, i think it writes the fieldNumber as -1
|
||||
* @throws IllegalArgumentException if fieldNumber is negative
|
||||
*/
|
||||
public FieldInfo fieldInfo(int fieldNumber) {
|
||||
return (fieldNumber >= 0) ? byNumber.get(fieldNumber) : null;
|
||||
if (fieldNumber < 0) {
|
||||
throw new IllegalArgumentException("Illegal field number: " + fieldNumber);
|
||||
}
|
||||
return byNumber.get(fieldNumber);
|
||||
}
|
||||
|
||||
static final class FieldNumbers {
|
||||
|
|
Loading…
Reference in New Issue