Ackel Filia created LUCENE-9343:
-----------------------------------

             Summary: EnumFieldSource throws AssertionError
                 Key: LUCENE-9343
                 URL: https://issues.apache.org/jira/browse/LUCENE-9343
             Project: Lucene - Core
          Issue Type: Bug
          Components: core/query/scoring
    Affects Versions: 8.5.1
            Reporter: Ackel Filia


When a doc id is smaller than a previsou one, I obtain an AssertionError. I 
check the Lucene code, and find that it is thrown from the following code of 
EnumFieldSource:
{code:java}
 public FunctionValues getValues(Map context, LeafReaderContext readerContext) 
throws IOException {
    final NumericDocValues arr = DocValues.getNumeric(readerContext.reader(), 
field);    return new IntDocValues(this) {
      final MutableValueInt val = new MutableValueInt();      int lastDocID;    
  private int getValueForDoc(int doc) throws IOException {
        if (doc < lastDocID) {
          throw new AssertionError("docs were sent out-of-order: lastDocID=" + 
lastDocID + " vs doc=" + doc);
        }
        lastDocID = doc;
        int curDocID = arr.docID();
        if (doc > curDocID) {
          curDocID = arr.advance(doc);
        }
        if (doc == curDocID) {
          return (int) arr.longValue();
        } else {
          return 0;
        }
      }
}{code}
My code does not catch the exception. It catches IllegalArgumentException, 
because Lucene throws the exceptions for similar problems:

DocTermsIndexDocValues:
{code:java}
 protected int getOrdForDoc(int doc) throws IOException {
    if (doc < lastDocID) {
      throw new IllegalArgumentException("docs were sent out-of-order: 
lastDocID=" + lastDocID + " vs docID=" + doc);
    }
    lastDocID = doc;
    int curDocID = termsIndex.docID();
    if (doc > curDocID) {
      curDocID = termsIndex.advance(doc);
    }
    if (doc == curDocID) {
      return termsIndex.ordValue();
    } else {
      return -1;
    }
  }
{code}
BytesRefFieldSource:
{code:java}
  private BytesRef getValueForDoc(int doc) throws IOException {
          if (doc < lastDocID) {
            throw new IllegalArgumentException("docs were sent out-of-order: 
lastDocID=" + lastDocID + " vs docID=" + doc);
          }
          lastDocID = doc;
          int curDocID = binaryValues.docID();
          if (doc > curDocID) {
            curDocID = binaryValues.advance(doc);
          }
          if (doc == curDocID) {
            return binaryValues.binaryValue();
          } else {
            return null;
          }
        }
{code}
FloatFieldSource:
{code:java}
 private float getValueForDoc(int doc) throws IOException {
        if (doc < lastDocID) {
          throw new IllegalArgumentException("docs were sent out-of-order: 
lastDocID=" + lastDocID + " vs docID=" + doc);
        }
        lastDocID = doc;
        int curDocID = arr.docID();
        if (doc > curDocID) {
          curDocID = arr.advance(doc);
        }
        if (doc == curDocID) {
          return Float.intBitsToFloat((int)arr.longValue());
        } else {
          return 0f;
        }
      }
{code}
 EnumFieldSource throws a wrong exception. Can this problem be fixed?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to