Re: ArrayIndexOutOfBoundsException during DocValues facet count calculation

"Uwe Schindler via java-user" <[email protected]> Mon, 29 Jun 2026 09:22:04 +0200
Newsgroups gmane.comp.jakarta.lucene.user
Message-ID <[email protected]>
--------------XQYg01nKdZYIcboT5cX0ARgE
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi,

actually, FixedBitSet is a general purpose class provided by Apache 
Lucene. For performance reasons, this class does not do any parameter 
checks (only with the assertion that is not ran on production code). 
Therefor the exception happens later than it would happen in 
conventional "safe" bitsets.

As we do not have a stack trace in whcih context the error occurs, we 
can't figure out if the method is called from Lucene or Solr code. As it 
is facetting code it can come from both, because Solr also uses that bitset.

To get a better insight:

  * enable assertions in production code: Run Solr's JVM with "-ea"
    parameter to enable assertions. Add this to the command line options
    (next to garbage collector) and try again. Please be aware that this
    slows down a lot!
  * give us a full stack trace

Uwe

Am 26.06.2026 um 14:21 schrieb Ufuk YILMAZ via java-user:
> I've debugged a weird error I'm getting from Solr, which turned out to 
> be coming from lucene.
>
> For a particular search (it doesn't happen with other searches as far 
> as I could see), during the facet calculation (DocValues facet), at 
> this line:
>
> https://github.com/apache/lucene/blob/f965e930673c1f5cb478dc6a8907f5fc4ef7b539/lucene/core/src/java/org/apache/lucene/util/FixedBitSet.java#L297 
>
>
>   private int nextSetBitInRange(int start, int upperBound) {
>     // Depends on the ghost bits being clear!
>     assert start >= 0 && start < numBits : "index=" + start + ", 
> numBits=" + numBits;
>     assert start < upperBound : "index=" + start + ", upperBound=" + 
> upperBound;
>     assert upperBound <= numBits : "upperBound=" + upperBound + ", 
> numBits=" + numBits;
>     int i = start >> 6;
>     long word = bits[i] >> start; // skip all the bits to the right of 
> index
>
> "start" is 46536, "upperBound" is 46492 and "i" is 727:
>
> long word = bits[i] >> start; // skip all the bits to the right of index
>
> the above line throws an exception:
>
> java.lang.ArrayIndexOutOfBoundsException: Index 727 out of bounds for 
> length 727
>
> I don't know if I can reproduce this error with a few documents and a 
> simple search, because it is pretty elusive. For example, if I just 
> reindex, the exception goes away.
>
> When I use another facet calculation algorihtm in Solr (e.g. "enum"), 
> the error goes away. It's only when docvalues is used.
>
> Could you point me in a direction to maybe better reproduce it with a 
> specific set of documents, or debug it better?
>
> --Ufuk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
-- 
Uwe Schindler
Achterdiek 19, D-28357 Bremen
https://www.thetaphi.de
eMail:[email protected]

--------------XQYg01nKdZYIcboT5cX0ARgE--