This is an automated email from the ASF dual-hosted git repository. thomasm pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/trunk by this push: new cc679212ea OAK-11929: NullPointerException in SecureSortedSetDocValuesFacetCounts (#2510) cc679212ea is described below commit cc679212eaa1e2d35c5c47f5262e7afded9c092d Author: Marvin <95419378+chlinesau...@users.noreply.github.com> AuthorDate: Wed Sep 17 15:40:06 2025 +0200 OAK-11929: NullPointerException in SecureSortedSetDocValuesFacetCounts (#2510) * IssueToBeCreated: fix NullPointerException in SecureSortedSetDocValuesFacetCounts * OAK-11929: Move tests to FacetCommonTest --------- Co-authored-by: marvinw <marv...@adobe.com> --- .../util/SecureSortedSetDocValuesFacetCounts.java | 13 +++--- .../oak/plugins/index/FacetCommonTest.java | 49 ++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/SecureSortedSetDocValuesFacetCounts.java b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/SecureSortedSetDocValuesFacetCounts.java index 2bb1397b94..899dcf1b42 100644 --- a/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/SecureSortedSetDocValuesFacetCounts.java +++ b/oak-lucene/src/main/java/org/apache/jackrabbit/oak/plugins/index/lucene/util/SecureSortedSetDocValuesFacetCounts.java @@ -150,11 +150,11 @@ class SecureSortedSetDocValuesFacetCounts extends SortedSetDocValuesFacetCounts while (ord != SortedSetDocValues.NO_MORE_ORDS) { termsEnum.seekExact(ord); String facetDVTerm = termsEnum.term().utf8ToString(); - String [] facetDVDimPaths = FacetsConfig.stringToPath(facetDVTerm); + String[] facetDVDimPaths = FacetsConfig.stringToPath(facetDVTerm); - // first element is dimention name + // first element is dimension name for (int i = 1; i < facetDVDimPaths.length; i++) { - markInaccessbile(facetDVDimPaths[i]); + markInaccessible(facetDVDimPaths[i]); } ord = docValues.nextOrd(); @@ -162,8 +162,11 @@ class SecureSortedSetDocValuesFacetCounts extends SortedSetDocValuesFacetCounts } } - void markInaccessbile(@NotNull String label) { - inaccessibleCounts[labelToIndexMap.get(label)]++; + void markInaccessible(@NotNull String label) { + Integer index = labelToIndexMap.get(label); + if (index != null) { + inaccessibleCounts[index]++; + } } LabelAndValue[] updateLabelAndValue() { diff --git a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/FacetCommonTest.java b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/FacetCommonTest.java index 65783179a8..4928b2a754 100644 --- a/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/FacetCommonTest.java +++ b/oak-search/src/test/java/org/apache/jackrabbit/oak/plugins/index/FacetCommonTest.java @@ -42,6 +42,7 @@ import java.util.stream.Collectors; import static org.apache.jackrabbit.commons.JcrUtils.getOrCreateByPath; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.FACETS; +import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_FACETS_TOP_CHILDREN; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_RANDOM_SEED; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_REFRESH_DEFN; import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConstants.PROP_SECURE_FACETS; @@ -53,6 +54,7 @@ import static org.apache.jackrabbit.oak.plugins.index.search.FulltextIndexConsta import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; public abstract class FacetCommonTest extends AbstractJcrTest { private static final Logger LOG = LoggerFactory.getLogger(AbstractJcrTest.class); @@ -329,6 +331,46 @@ public abstract class FacetCommonTest extends AbstractJcrTest { facetsWithMultiValueProperty(PROP_SECURE_FACETS_VALUE_STATISTICAL); } + @Test + public void inaccessibleFacetsNotCounted() throws Exception { + Node node = allow(getOrCreateByPath("/parent", "oak:Unstructured", adminSession)); + Node doc1 = createDocumentNode(node, "doc1", "apple"); + createDocumentNode(node, "doc2", "apple"); + createDocumentNode(node, "doc3", "banana"); + + deny(doc1); + adminSession.save(); + + assertEventually(() -> { + Map<String, Integer> facets = getFacets(); + assertEquals(2, facets.size()); + assertEquals(Integer.valueOf(1), facets.get("apple")); + assertEquals(Integer.valueOf(1), facets.get("banana")); + }); + } + + @Test + public void inaccessibleFacetOutsideTopNAreIgnored() throws Exception { + Node facetConfig = getOrCreateByPath(indexNode.getPath() + "/" + FACETS, "nt:unstructured", adminSession); + facetConfig.setProperty(PROP_FACETS_TOP_CHILDREN, 1); + adminSession.save(); + + Node node = allow(getOrCreateByPath("/parent", "oak:Unstructured", adminSession)); + createDocumentNode(node, "doc1", "apple"); + createDocumentNode(node, "doc2", "apple"); + Node doc3 = createDocumentNode(node, "doc3", "banana"); + + deny(doc3); + adminSession.save(); + + assertEventually(() -> { + Map<String, Integer> facets = getFacets(); + assertEquals(1, facets.size()); + assertEquals(Integer.valueOf(2), facets.get("apple")); + assertFalse(facets.containsKey("banana")); + }); + } + public void facetsWithMultiValueProperty(String facetType) throws Exception { Node facetConfig = getOrCreateByPath(indexNode.getPath() + "/" + FACETS, "nt:unstructured", adminSession); facetConfig.setProperty(PROP_SECURE_FACETS, facetType); @@ -397,6 +439,13 @@ public abstract class FacetCommonTest extends AbstractJcrTest { return queryResult; } + private Node createDocumentNode(Node parent, String docName, String fooValue) throws RepositoryException { + Node doc = parent.addNode(docName); + doc.setProperty("cons", "val"); + doc.setProperty("foo", fooValue); + return doc; + } + protected void assertEventually(Runnable r) { TestUtil.assertEventually(r, ((repositoryOptionsUtil.isAsync() ? repositoryOptionsUtil.defaultAsyncIndexingTimeInSeconds : 0) + 3000) * 5); }