Skip to content

Commit

Permalink
SOLR-15591 / Avoid needless catch by checking condition (#340)
Browse files Browse the repository at this point in the history
Co-authored-by: Eric Pugh <[email protected]>
  • Loading branch information
charlygrappa and epugh authored Jun 22, 2024
1 parent 1dfe095 commit 7d57f3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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-gather
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7d57f3e

Please sign in to comment.