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 7df3eb5bddb SOLR-17394: Address review feedback
7df3eb5bddb is described below

commit 7df3eb5bddba4898d909f46d7b9af374d327a5cb
Author: Jason Gerlowski <[email protected]>
AuthorDate: Thu Aug 15 21:21:41 2024 -0400

    SOLR-17394: Address review feedback
    
    Addresses some feedback from David Smiley regarding control flow and
    Optional-usage that came in after the original PR was merged.
---
 .../java/org/apache/solr/handler/IndexFetcher.java    | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java 
b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
index d439f7196cd..dab68b339b7 100644
--- a/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
+++ b/solr/core/src/java/org/apache/solr/handler/IndexFetcher.java
@@ -71,7 +71,6 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Properties;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
@@ -1999,7 +1998,7 @@ public class IndexFetcher {
                   "Unexpected status code [%d] when downloading file [%s].",
                   responseStatus,
                   fileName);
-          closeStreamAndThrowIOE(is, errorMsg, Optional.empty());
+          closeStreamAndBuildIOE(is, errorMsg, null);
         }
 
         if (useInternalCompression) {
@@ -2007,20 +2006,18 @@ public class IndexFetcher {
         }
         return new FastInputStream(is);
       } catch (Exception e) {
-        closeStreamAndThrowIOE(is, "Could not download file '" + fileName + 
"'", Optional.of(e));
+        final var ioe = closeStreamAndBuildIOE(is, "Could not download file '" 
+ fileName + "'", e);
+        throw ioe;
       }
-
-      // Unreachable b/c closeStreamAndThrowIOE will always throw
-      return null;
     }
 
-    private void closeStreamAndThrowIOE(
-        InputStream is, String exceptionMessage, Optional<Exception> e) throws 
IOException {
+    private IOException closeStreamAndBuildIOE(
+        InputStream is, String exceptionMessage, Exception e) {
       IOUtils.closeQuietly(is);
-      if (e.isPresent()) {
-        throw new IOException(exceptionMessage, e.get());
+      if (e != null) {
+        return new IOException(exceptionMessage, e);
       }
-      throw new IOException(exceptionMessage);
+      return new IOException(exceptionMessage);
     }
   }
 

Reply via email to