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

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


The following commit(s) were added to refs/heads/branch_9x by this push:
     new aaacaee4472 SOLR-15591 / Avoid needless catch by checking condition 
(#340)
aaacaee4472 is described below

commit aaacaee447290cee2cd84ab9422b25a7789312cb
Author: Carlos Grappa <[email protected]>
AuthorDate: Sat Jun 22 12:10:32 2024 -0300

    SOLR-15591 / Avoid needless catch by checking condition (#340)
    
    
    Co-authored-by: Eric Pugh <[email protected]>
---
 solr/CHANGES.txt                                   |  2 ++
 .../java/org/apache/solr/util/ExternalPaths.java   | 26 ++++++++++++----------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 412fdd1b6a2..5759f229d53 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -37,6 +37,8 @@ Improvements
 
 * SOLR-17331: OrderedNodePlacementPlugin will give an even more optimal 
replica placements during ReplicaMigration commands (Houston Putman, Yohann 
Callea)
 
+* SOLR-15591: Make using debugger in Solr easier by avoiding NPE in 
ExternalPaths.determineSourceHome.  (@charlygrappa via Eric Pugh)
+
 Optimizations
 ---------------------
 * SOLR-17257: Both Minimize Cores and the Affinity replica placement 
strategies would over-gather
diff --git 
a/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java 
b/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
index 122b01829a2..8d21f9e3e84 100644
--- a/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
+++ b/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java
@@ -17,6 +17,7 @@
 package org.apache.solr.util;
 
 import java.io.File;
+import java.net.URL;
 
 /**
  * Some tests need to reach outside the classpath to get certain resources 
(e.g. the example
@@ -28,8 +29,8 @@ public class ExternalPaths {
 
   /**
    * The main directory path for the solr source being built if it can be 
determined. If it can not
-   * be determined -- possily because the current context is a client code 
base using hte test
-   * frameowrk -- then this variable will be null.
+   * be determined -- possibly because the current context is a client code 
base using the test
+   * framework -- then this variable will be null.
    *
    * <p>Note that all other static paths available in this class are derived 
from the source home,
    * and if it is null, those paths will just be relative to 'null' and may 
not be meaningful.
@@ -66,23 +67,24 @@ public class ExternalPaths {
    */
   static String determineSourceHome() {
     try {
-      File file;
-      try {
-        file = new File("solr/conf");
-        if (!file.exists()) {
-          file = new 
File(ExternalPaths.class.getClassLoader().getResource("solr/conf").toURI());
+      File file = new File("solr/conf");
+      if (!file.exists()) {
+        URL resourceUrl = 
ExternalPaths.class.getClassLoader().getResource("solr/conf");
+        if (resourceUrl != null) {
+          file = new File(resourceUrl.toURI());
+        } else {
+          // If there is no "solr/conf" in the classpath, fall back to 
searching from the current
+          // directory.
+          file = new File(System.getProperty("tests.src.home", "."));
         }
-      } catch (Exception e) {
-        // If there is no "solr/conf" in the classpath, fall back to searching 
from the current
-        // directory.
-        file = new File(System.getProperty("tests.src.home", "."));
       }
+
       File base = file.getAbsoluteFile();
       while (!(new File(base, "solr/CHANGES.txt").exists()) && null != base) {
         base = base.getParentFile();
       }
       return (null == base) ? null : new File(base, "solr/").getAbsolutePath();
-    } catch (RuntimeException e) {
+    } catch (Exception e) {
       // all bets are off
       return null;
     }

Reply via email to