You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/08/22 18:42:20 UTC

[lucene-solr] 01/22: @581 Fix NPE race.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 0c899c68f994319f57a7185c3e3c98808bb7f3f1
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Thu Aug 20 10:42:42 2020 -0500

    @581 Fix NPE race.
---
 .../java/org/apache/solr/common/cloud/ZkStateReader.java   | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index 8002af9..4e2cd2c 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -718,8 +718,8 @@ public class ZkStateReader implements SolrCloseable {
     public DocCollection get(boolean allowCached) {
       gets.incrementAndGet();
       if (!allowCached || lastUpdateTime < 0 || System.nanoTime() - lastUpdateTime > LAZY_CACHE_TIME) {
-        boolean shouldFetch = true;
-        if (cachedDocCollection != null) {
+        DocCollection fcachedDocCollection = cachedDocCollection;
+        if (fcachedDocCollection != null) {
           Stat exists = null;
           try {
             exists = zkClient.exists(getCollectionPath(collName), null);
@@ -727,14 +727,12 @@ public class ZkStateReader implements SolrCloseable {
             ParWork.propegateInterrupt(e);
             throw new SolrException(ErrorCode.SERVER_ERROR, e);
           }
-          if (exists != null && exists.getVersion() == cachedDocCollection.getZNodeVersion()) {
-            shouldFetch = false;
+          if (exists != null && exists.getVersion() == fcachedDocCollection.getZNodeVersion()) {
+            return fcachedDocCollection;
           }
         }
-        if (shouldFetch) {
-          cachedDocCollection = getCollectionLive(ZkStateReader.this, collName);
-          lastUpdateTime = System.nanoTime();
-        }
+        cachedDocCollection = getCollectionLive(ZkStateReader.this, collName);
+        lastUpdateTime = System.nanoTime();
       }
       return cachedDocCollection;
     }