Description
Running the following query select [rep:facet(simple/tags)] from [nt:base] where contains([text], 'ipsum') with the following content
/content/foo - text = "lorem lorem" + simple/ - tags = ["tag1", "tag2"] /content/bar - text = "lorem ipsum"
runs in the following NPE
java.lang.NullPointerException at org.apache.jackrabbit.oak.plugins.index.lucene.util.FilteredSortedSetDocValuesFacetCounts.getTopChildren(FilteredSortedSetDocValuesFacetCounts.java:63) at org.apache.lucene.facet.MultiFacets.getTopChildren(MultiFacets.java:52) at org.apache.jackrabbit.oak.plugins.index.lucene.LucenePropertyIndex$LucenePathCursor$2.getValue(LucenePropertyIndex.java:1646) ... 38 more
This is because the result set for the query only contains /content/bar and with that the count of the dimension simple/tag is 0. For that case SortedSetDocValuesFacetCounts#getDim() returns null and so does getTopChildren.
This expected behaviour is properly handled in LucenePropertyIndex.java#L1647 but not in FilteredSortedSetDocValuesFacetCounts.java#L63 where topChildren is dereferenced without null check.
To workaround that secure facets can be set to false, though the default value is true.