From 8445d20f5db1a2a0dcc09c9495b064ca5fea1afb Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 11 Jul 2011 13:44:42 +0000 Subject: [PATCH] SOLR-2564: Fixed ArrayIndexOutOfBoundsException when using simple format git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1145173 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/java/org/apache/solr/search/Grouping.java | 2 +- .../test/org/apache/solr/TestGroupingSearch.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/solr/core/src/java/org/apache/solr/search/Grouping.java b/solr/core/src/java/org/apache/solr/search/Grouping.java index 8fff90b2a92..fd4fe6a2d1c 100755 --- a/solr/core/src/java/org/apache/solr/search/Grouping.java +++ b/solr/core/src/java/org/apache/solr/search/Grouping.java @@ -585,7 +585,7 @@ public class Grouping { } } - int len = Math.min(numGroups, docsGathered); + int len = docsGathered - offset; if (offset > len) { len = 0; } diff --git a/solr/core/src/test/org/apache/solr/TestGroupingSearch.java b/solr/core/src/test/org/apache/solr/TestGroupingSearch.java index f5f91b67844..17ce2a12dde 100644 --- a/solr/core/src/test/org/apache/solr/TestGroupingSearch.java +++ b/solr/core/src/test/org/apache/solr/TestGroupingSearch.java @@ -182,7 +182,22 @@ public class TestGroupingSearch extends SolrTestCaseJ4 { ); } + @Test + public void testGroupingSimpleFormatArrayIndexOutOfBoundsException() throws Exception { + assertU(add(doc("id", "1"))); + assertU(add(doc("id", "2"))); + assertU(add(doc("id", "3"))); + assertU(commit()); + assertJQ( + req("q", "*:*", "start", "1", "group", "true", "group.field", "id", "group.main", "true"), + "/response=={'numFound':3,'start':1,'docs':[{'id':'2'},{'id':'3'}]}" + ); + assertJQ( + req("q", "*:*", "start", "1", "rows", "1", "group", "true", "group.field", "id", "group.main", "true"), + "/response=={'numFound':3,'start':1,'docs':[{'id':'2'}]}" + ); + } static String f = "foo_i"; static String f2 = "foo2_i";