Apache Solr open-source search software
SOLR-15591 / Avoid needless catch by checking condition (#340)
Carlos Grappa7d57f3e481d2
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 44a7af702b1..9ce1c138778 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -133,6 +133,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-gatherdiff --git a/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java b/solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.javaindex 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 offreturn null;}