Hibernate Lucene 8.1.1 Final Java 17 Composite Aggregations throw NPE when no aggregation result is found

We are using Hibernate with Lucene Backend 8.1.1 Final

After indexing our data, I am creating a composite with multiple aggregations with f.sum() on which I add a .filter() because I only want to target certain elements for the sum. There are cases where one of my aggregations does not find any hits in the index, which is expected. In that case I would expect to get “null” during the extraction of the aggregation sum result. But I get a Null Pointer Exception: Cannot invoke “java.lang.Long.longValue()” because “collector” is null.

I tracked down the issue within AbstractLuceneMetricNumericFieldAggregation as part of the extract(AggregationExtractContext context) method call. The collector which is of type Long (wrapper class) coming from the context.getCollectorResults(collectorKey) is null. On the next line, codec.getDomain() returns a LuceneLongDomain, on which the sortedDocValueToTerm(collector) method is called. Since the method sortedDocValueToTerm expects not a Long but the primitive type long, it tries to convert the collector which is null to its primitive type, triggering the null pointer exception.

Is there current development ongoing in this issue (as composite aggregations is an incubating feature? Or a workaround?

Hi @brandsi

Thanks for reporting the issue. I can confirm that I can also reproduce it.

I’ve created Jira to track the issue.
As for the workaround … you could try downgrading, but then you may encounter this one instead: Jira .

I’ll try to prepare the fix and release it early this week.

Hi @mbekhta

Thanks for your quick response.

I don’t think downgrading is an option. As you mentioned, we would get the other exception.

Thanks for working on the fix. Would it be part of a new version like 8.1.2.Final?

Best Regards

Simon

Yes, that would be a plan (to include the fix in 8.1.2.Final). :+1:

Cool stuff, thank you. I see you normally omit dates on your releases page, but do you have an indication when the release containing the fix would be available?

but do you have an indication when the release containing the fix would be available?

8.1.2.Final should be on central now :slightly_smiling_face::

Maven Central: org.hibernate.search:hibernate-search-backend-lucene:8.1.2.Final