Skip to content

Apache Lucene open-source search software

SOLR-13206: Fix AIOOBE when group.facet is specified with group.query

Munendra S N1fc416404cbb
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 5f946349b6c..772973bde6e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -81,6 +81,11 @@ Improvements
* SOLR-12368: Support InPlace DV updates for a field that does not yet exist in any documents
(hossman, Simon Willnauer, Adrien Grand, Munendra S N)
+Bug Fixes
+----------------------
+
+* SOLR-13206: Fix AIOOBE when group.facet is specified with group.query and return proper error code. (Marek, Munendra S N)
+
================== 8.2.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java
index 92f9a66dea0..561df4f4c7d 100644
--- a/solr/core/src/java/org/apache/solr/request/SimpleFacets.java
+++ b/solr/core/src/java/org/apache/solr/request/SimpleFacets.java
@@ -38,6 +38,7 @@ import java.util.concurrent.Semaphore;
import java.util.function.Predicate;
import java.util.stream.Stream;
+import org.apache.commons.lang3.ArrayUtils;
import org.apache.lucene.index.ExitableDirectoryReader;
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
@@ -705,7 +706,8 @@ public class SimpleFacets {
String prefix,
Predicate<BytesRef> termFilter) throws IOException {
GroupingSpecification groupingSpecification = rb.getGroupingSpec();
- final String groupField = groupingSpecification != null ? groupingSpecification.getFields()[0] : null;
+ String[] groupFields = groupingSpecification != null? groupingSpecification.getFields(): null;
+ final String groupField = ArrayUtils.isNotEmpty(groupFields) ? groupFields[0] : null;
if (groupField == null) {
throw new SolrException (
SolrException.ErrorCode.BAD_REQUEST,
diff --git a/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java b/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java
index 83c5b3a5189..ccdd65fbcac 100644
--- a/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java
+++ b/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java
@@ -3303,6 +3303,39 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {
);
}
+
+ public void testGroupFacetErrors() {
+ ModifiableSolrParams params = params("q", "*:*", "group", "true", "group.query", "myfield_s:*",
+ "facet", "true", "group.facet", "true");
+
+ // with facet.field
+ SolrException ex = expectThrows(SolrException.class, () -> {
+ h.query(req(params, "facet.field", "myfield_s"));
+ });
+ assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
+ assertTrue(ex.getMessage().contains("Specify the group.field as parameter or local parameter"));
+
+ // with facet.query
+ ex = expectThrows(SolrException.class, () -> {
+ h.query(req(params, "facet.query", "myfield_s:*"));
+ });
+ assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
+ assertTrue(ex.getMessage().contains("Specify the group.field as parameter or local parameter"));
+
+ // with facet.range
+ ex = expectThrows(SolrException.class, () -> h.query(req(params, "facet.range", "range_facet_l",
+ "facet.range.start", "43", "facet.range.end", "450", "facet.range.gap", "10"))
+ );
+ assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
+ assertTrue(ex.getMessage().contains("Specify the group.field as parameter or local parameter"));
+
+ // with facet.interval
+ ex = expectThrows(SolrException.class, () -> h.query(req(params, "facet.interval", "range_facet_l",
+ "f.range_facet_l.facet.interval.set", "(43,60]"))
+ );
+ assertEquals(ErrorCode.BAD_REQUEST.code, ex.code());
+ assertTrue(ex.getMessage().contains("Interval Faceting can't be used with group.facet"));
+ }
public void testRangeFacetingBadRequest() {
String field = "range_facet_l";