diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 77fd3f27edc..72851a0c00a 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -92,6 +92,8 @@ Bug Fixes * SOLR-13521: Fix input parameter handling in SchemaRequest.DynamicField and SchemaRequest.FieldTypes (Schema API) (Tomás Fernández Löbbe) +* SOLR-13496: Fix distributed grouping related NullPointerException in JSONWriter.writeSolrDocument (Christine Poerschke) + Other Changes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java b/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java index 2c622d4ff09..6757d9c0603 100644 --- a/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java +++ b/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java @@ -28,6 +28,7 @@ import org.apache.lucene.search.TotalHits; import org.apache.lucene.search.grouping.GroupDocs; import org.apache.lucene.search.grouping.TopGroups; import org.apache.lucene.util.BytesRef; +import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; @@ -90,9 +91,7 @@ public class GroupedEndResultTransformer implements EndResultTransformer { docList.setMaxScore(group.maxScore); } docList.setStart(rb.getGroupingSpec().getWithinGroupOffset()); - for (ScoreDoc scoreDoc : group.scoreDocs) { - docList.add(solrDocumentSource.retrieve(scoreDoc)); - } + retrieveAndAdd(docList, solrDocumentSource, group.scoreDocs); groupResult.add("doclist", docList); groups.add(groupResult); } @@ -110,9 +109,7 @@ public class GroupedEndResultTransformer implements EndResultTransformer { docList.setMaxScore(queryCommandResult.getMaxScore()); } docList.setStart(rb.getGroupingSpec().getWithinGroupOffset()); - for (ScoreDoc scoreDoc :queryCommandResult.getTopDocs().scoreDocs){ - docList.add(solrDocumentSource.retrieve(scoreDoc)); - } + retrieveAndAdd(docList, solrDocumentSource, queryCommandResult.getTopDocs().scoreDocs); command.add("doclist", docList); commands.add(entry.getKey(), command); } @@ -120,4 +117,13 @@ public class GroupedEndResultTransformer implements EndResultTransformer { rb.rsp.add("grouped", commands); } + private static void retrieveAndAdd(SolrDocumentList solrDocumentList, SolrDocumentSource solrDocumentSource, ScoreDoc[] scoreDocs) { + for (ScoreDoc scoreDoc : scoreDocs) { + SolrDocument solrDocument = solrDocumentSource.retrieve(scoreDoc); + if (solrDocument != null) { + solrDocumentList.add(solrDocument); + } + } + } + }