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

gerlowskija pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 79503c1afe5 SOLR-16391: Fix CoreStatus NullPointerException
79503c1afe5 is described below

commit 79503c1afe55beed1bdd6e66a287be1835340cbc
Author: Jason Gerlowski <gerlowsk...@apache.org>
AuthorDate: Tue Feb 25 07:10:09 2025 -0500

    SOLR-16391: Fix CoreStatus NullPointerException
    
    A previous recent commit (5fafab) introduced a NullPointerException when
    a Boolean was in a conditional without first checking for 'null'.  This
    commit fixes this error and another related CoreStatus-related test
    failure.
---
 .../org/apache/solr/handler/admin/api/CoreStatus.java |  8 ++++++--
 .../apache/solr/handler/TestReplicationHandler.java   | 19 ++++++++-----------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git 
a/solr/core/src/java/org/apache/solr/handler/admin/api/CoreStatus.java 
b/solr/core/src/java/org/apache/solr/handler/admin/api/CoreStatus.java
index 9f7f27e3146..631e1f89488 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/api/CoreStatus.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/CoreStatus.java
@@ -48,6 +48,8 @@ import org.apache.solr.util.RefCounted;
  */
 public class CoreStatus extends CoreAdminAPIBase implements CoreApis.GetStatus 
{
 
+  private static boolean INDEX_INFO_DEFAULT_VALUE = true;
+
   @Inject
   public CoreStatus(
       CoreContainer coreContainer,
@@ -60,13 +62,15 @@ public class CoreStatus extends CoreAdminAPIBase implements 
CoreApis.GetStatus {
   @Override
   @PermissionName(CORE_READ_PERM)
   public CoreStatusResponse getAllCoreStatus(Boolean indexInfo) throws 
IOException {
-    return fetchStatusInfo(coreContainer, null, indexInfo);
+    final var indexInfoNeeded = indexInfo == null ? INDEX_INFO_DEFAULT_VALUE : 
indexInfo;
+    return fetchStatusInfo(coreContainer, null, indexInfoNeeded);
   }
 
   @Override
   @PermissionName(CORE_READ_PERM)
   public CoreStatusResponse getCoreStatus(String coreName, Boolean indexInfo) 
throws IOException {
-    return fetchStatusInfo(coreContainer, coreName, indexInfo);
+    final var indexInfoNeeded = indexInfo == null ? INDEX_INFO_DEFAULT_VALUE : 
indexInfo;
+    return fetchStatusInfo(coreContainer, coreName, indexInfoNeeded);
   }
 
   public static CoreStatusResponse fetchStatusInfo(
diff --git 
a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java 
b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
index 800e172d98a..02098fb734d 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
@@ -52,6 +52,7 @@ import org.apache.solr.client.solrj.SolrClient;
 import org.apache.solr.client.solrj.SolrQuery;
 import org.apache.solr.client.solrj.SolrRequest;
 import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.request.CoresApi;
 import org.apache.solr.client.solrj.request.GenericSolrRequest;
 import org.apache.solr.client.solrj.request.QueryRequest;
 import org.apache.solr.client.solrj.request.UpdateRequest;
@@ -63,7 +64,6 @@ import org.apache.solr.common.SolrDocumentList;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.params.ModifiableSolrParams;
-import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.common.util.NamedList;
 import org.apache.solr.common.util.TimeSource;
 import org.apache.solr.core.CachingDirectoryFactory;
@@ -1676,18 +1676,15 @@ public class TestReplicationHandler extends 
SolrTestCaseJ4 {
     long timeSlept = 0;
 
     try (SolrClient adminClient = adminClient(jettySolrRunner)) {
-      SolrParams p = params("action", "status", "core", "collection1");
+      final var statusRequest = new CoresApi.GetCoreStatus("collection1");
       while (timeSlept < TIMEOUT) {
-        QueryRequest req = new QueryRequest(p);
-        req.setPath("/admin/cores");
         try {
-          NamedList<Object> data = adminClient.request(req);
-          for (String k : new String[] {"status", "collection1"}) {
-            Object o = data.get(k);
-            assertNotNull("core status rsp missing key: " + k, o);
-            data = (NamedList<Object>) o;
-          }
-          Date startTime = (Date) data.get("startTime");
+          final var statusResponse = 
statusRequest.process(adminClient).getParsed();
+          assertNotNull(statusResponse.status);
+          assertTrue(statusResponse.status.containsKey("collection1"));
+          final var coreStatus = statusResponse.status.get("collection1");
+          Date startTime = coreStatus.startTime;
+
           assertNotNull("core has null startTime", startTime);
           if (null == min || startTime.after(min)) {
             return startTime;

Reply via email to