sonatype-lift[bot] commented on code in PR #1182:
URL: https://github.com/apache/solr/pull/1182#discussion_r1166774519


##########
solr/core/src/java/org/apache/solr/util/SolrCLI.java:
##########
@@ -1504,26 +1260,24 @@ public static boolean safeCheckCollectionExists(String 
url, String collection) {
     return exists;
   }
 
-  public static boolean safeCheckCoreExists(String coreStatusUrl, String 
coreName) {
+  @SuppressWarnings("unchecked")
+  public static boolean safeCheckCoreExists(String solrUrl, String coreName) {
     boolean exists = false;
-    try {
+    try (var solrClient = getSolrClient(solrUrl)) {
       boolean wait = false;
       final long startWaitAt = System.nanoTime();
       do {
         if (wait) {
           final int clamPeriodForStatusPollMs = 1000;
           Thread.sleep(clamPeriodForStatusPollMs);
         }
-        Map<String, Object> existsCheckResult = getJson(coreStatusUrl);
-        @SuppressWarnings("unchecked")
-        Map<String, Object> status = (Map<String, Object>) 
existsCheckResult.get("status");
-        @SuppressWarnings("unchecked")
-        Map<String, Object> coreStatus = (Map<String, Object>) 
status.get(coreName);
-        @SuppressWarnings("unchecked")
-        Map<String, Object> failureStatus =
-            (Map<String, Object>) existsCheckResult.get("initFailures");
-        String errorMsg = (String) failureStatus.get(coreName);
-        final boolean hasName = coreStatus != null && 
coreStatus.containsKey(NAME);
+        NamedList<Object> existsCheckResult = 
CoreAdminRequest.getStatus(coreName, solrClient).getResponse();
+        NamedList<Object> status =
+          (NamedList)existsCheckResult.get("status");
+        NamedList<Object> coreStatus = (NamedList) status.get(coreName);
+        Map<String, Object> failureStatus = (Map<String, Object>) 
existsCheckResult.get("initFailures");
+        String errorMsg = (String)failureStatus.get(coreName);

Review Comment:
   <picture><img alt="14% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/14/display.svg";></picture>
   
   <b>*NULL_DEREFERENCE:</b>*  object `failureStatus` last assigned on line 
1278 could be null and is dereferenced at line 1279.
   
   ---
   
   <details><summary>ℹī¸ Expand to see all <b>@sonatype-lift</b> 
commands</summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   <b>Help us improve LIFT! (<i>Sonatype LiftBot external survey</i>)</b>
   
   Was this a good recommendation for you? <sub><small>Answering this survey 
will not impact your Lift settings.</small></sub>
   
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=491179443&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=491179443&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=491179443&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=491179443&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=491179443&lift_comment_rating=5)
 ]



##########
solr/core/src/java/org/apache/solr/util/SolrCLI.java:
##########
@@ -1504,26 +1260,24 @@ public static boolean safeCheckCollectionExists(String 
url, String collection) {
     return exists;
   }
 
-  public static boolean safeCheckCoreExists(String coreStatusUrl, String 
coreName) {
+  @SuppressWarnings("unchecked")
+  public static boolean safeCheckCoreExists(String solrUrl, String coreName) {
     boolean exists = false;
-    try {
+    try (var solrClient = getSolrClient(solrUrl)) {
       boolean wait = false;
       final long startWaitAt = System.nanoTime();
       do {
         if (wait) {
           final int clamPeriodForStatusPollMs = 1000;
           Thread.sleep(clamPeriodForStatusPollMs);
         }
-        Map<String, Object> existsCheckResult = getJson(coreStatusUrl);
-        @SuppressWarnings("unchecked")
-        Map<String, Object> status = (Map<String, Object>) 
existsCheckResult.get("status");
-        @SuppressWarnings("unchecked")
-        Map<String, Object> coreStatus = (Map<String, Object>) 
status.get(coreName);
-        @SuppressWarnings("unchecked")
-        Map<String, Object> failureStatus =
-            (Map<String, Object>) existsCheckResult.get("initFailures");
-        String errorMsg = (String) failureStatus.get(coreName);
-        final boolean hasName = coreStatus != null && 
coreStatus.containsKey(NAME);
+        NamedList<Object> existsCheckResult = 
CoreAdminRequest.getStatus(coreName, solrClient).getResponse();
+        NamedList<Object> status =
+          (NamedList)existsCheckResult.get("status");
+        NamedList<Object> coreStatus = (NamedList) status.get(coreName);

Review Comment:
   <picture><img alt="14% of developers fix this issue" 
src="https://lift.sonatype.com/api/commentimage/fixrate/14/display.svg";></picture>
   
   <b>*NULL_DEREFERENCE:</b>*  object `status` last assigned on line 1276 could 
be null and is dereferenced at line 1277.
   
   ---
   
   <details><summary>ℹī¸ Expand to see all <b>@sonatype-lift</b> 
commands</summary>
   
   You can reply with the following commands. For example, reply with 
***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this 
PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified 
`file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see 
its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) 
to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   <b>Help us improve LIFT! (<i>Sonatype LiftBot external survey</i>)</b>
   
   Was this a good recommendation for you? <sub><small>Answering this survey 
will not impact your Lift settings.</small></sub>
   
   [ [🙁 Not 
relevant](https://www.sonatype.com/lift-comment-rating?comment=491180267&lift_comment_rating=1)
 ] - [ [😕 Won't 
fix](https://www.sonatype.com/lift-comment-rating?comment=491180267&lift_comment_rating=2)
 ] - [ [😑 Not critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=491180267&lift_comment_rating=3)
 ] - [ [🙂 Critical, will 
fix](https://www.sonatype.com/lift-comment-rating?comment=491180267&lift_comment_rating=4)
 ] - [ [😊 Critical, fixing 
now](https://www.sonatype.com/lift-comment-rating?comment=491180267&lift_comment_rating=5)
 ]



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to