Apache Lucene open-source search software
SOLR-7866: Harden code to prevent an unhandled NPE when trying to determine the max value of the version field.
Timothy Potter7cdc63f3d4f7
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 20bf410805f..d9f777300a3 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -282,6 +282,9 @@ Bug Fixes* SOLR-7818: Fixed distributed stats to be calculated for all the query terms. Earlier the stats were calculated withthe terms that are present in the last shard of a distributed request. (Varun Thacker, Anshum Gupta)+* SOLR-7866: VersionInfo caused an unhandled NPE when trying to determine the max value for the+ version field. (Timothy Potter)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/update/VersionInfo.java b/solr/core/src/java/org/apache/solr/update/VersionInfo.javaindex ff2345a632e..54ced7807ac 100644--- a/solr/core/src/java/org/apache/solr/update/VersionInfo.java+++ b/solr/core/src/java/org/apache/solr/update/VersionInfo.java@@ -231,8 +231,9 @@ public class VersionInfo {// if indexed, then we have terms to get the max fromif (versionField.indexed()) {Terms versionTerms = searcher.getLeafReader().terms(versionFieldName);- if (versionTerms != null) {- maxVersionInIndex = NumericUtils.getMaxLong(versionTerms);+ Long max = (versionTerms != null) ? NumericUtils.getMaxLong(versionTerms) : null;+ if (max != null) {+ maxVersionInIndex = max.longValue();log.info("Found MAX value {} from Terms for {} in index", maxVersionInIndex, versionFieldName);} else {log.info("No terms found for {}, cannot seed version bucket highest value from index", versionFieldName);diff --git a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.javaindex 71e336d3811..c08b2472e57 100644--- a/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java+++ b/solr/core/src/test/org/apache/solr/cloud/DistributedVersionInfoTest.java@@ -88,6 +88,11 @@ public class DistributedVersionInfoTest extends AbstractFullDistribZkTestBase {List<Replica> notLeaders =ensureAllReplicasAreActive(testCollectionName, shardId, 1, rf, maxWaitSecsToSeeAllActive);+ // start by reloading the empty collection so we try to calculate the max from an empty index+ reloadCollection(leader, testCollectionName);+ notLeaders =+ ensureAllReplicasAreActive(testCollectionName, shardId, 1, rf, maxWaitSecsToSeeAllActive);+sendDoc(1);cloudClient.commit();