Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-18092: fix solr-test-framework for 3rd party -- ExternalPaths NPE (#4225)

Dawid Weiss1da74ce73a6d
diff --git a/changelog/unreleased/SOLR-18171-test-framework-external-usage-NPE.yml b/changelog/unreleased/SOLR-18171-test-framework-external-usage-NPE.yml
new file mode 100644
index 00000000000..d22fa358c5a
--- /dev/null
+++ b/changelog/unreleased/SOLR-18171-test-framework-external-usage-NPE.yml
@@ -0,0 +1,12 @@
+title: solr-test-framework isn't usable outside Solr, a 10.0 regression.
+type: fixed
+authors:
+ - name: Dawid Weiss
+ - name: David Smiley
+ - name: Eric Pugh
+ - name: hossman
+links:
+ - name: SOLR-18092
+ url: https://issues.apache.org/jira/browse/SOLR-18092
+
+
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
index d7a0475fc7b..d1c3e539bf1 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCase.java
@@ -25,7 +25,6 @@ import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;
import java.lang.invoke.MethodHandles;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
@@ -130,7 +129,7 @@ public class SolrTestCase extends LuceneTestCase {
return;
}
final Path extPath = ExternalPaths.DEFAULT_CONFIGSET;
- if (Files.isReadable(extPath /* implies exists() */) && Files.isDirectory(extPath)) {
+ if (extPath != null) {
log.info(
"Setting '{}' system property to test-framework derived value of '{}'",
ConfigSetService.SOLR_CONFIGSET_DEFAULT_CONFDIR,
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 940ec58b9e9..638a6fe3774 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
@@ -30,38 +30,38 @@ import org.apache.solr.common.SolrException;
public class ExternalPaths {
/**
- * The main directory path for the solr source being built if it can be determined. If it can not
+ * The main directory path for the solr source being built if it can be determined. If it cannot
* 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.
+ * and if it is null, those paths will be null as well.
*/
- public static final Path SOURCE_HOME = determineSourceHome();
+ public static final Path SOURCE_HOME = determineSourceHome(); // absolute
/**
* @see #SOURCE_HOME
*/
- public static Path WEBAPP_HOME = SOURCE_HOME.resolve("webapp/web").toAbsolutePath();
+ public static Path WEBAPP_HOME = SOURCE_HOME == null ? null : SOURCE_HOME.resolve("webapp/web");
/**
* @see #SOURCE_HOME
*/
public static Path DEFAULT_CONFIGSET =
- SOURCE_HOME.resolve("server/solr/configsets/_default/conf").toAbsolutePath();
+ SOURCE_HOME == null ? null : SOURCE_HOME.resolve("server/solr/configsets/_default/conf");
/**
* @see #SOURCE_HOME
*/
public static Path TECHPRODUCTS_CONFIGSET =
- SOURCE_HOME
- .resolve("server/solr/configsets/sample_techproducts_configs/conf")
- .toAbsolutePath();
+ SOURCE_HOME == null
+ ? null
+ : SOURCE_HOME.resolve("server/solr/configsets/sample_techproducts_configs/conf");
/**
* @see #SOURCE_HOME
*/
- public static Path SERVER_HOME = SOURCE_HOME.resolve("server/solr").toAbsolutePath();
+ public static Path SERVER_HOME = SOURCE_HOME == null ? null : SOURCE_HOME.resolve("server/solr");
/**
* Ugly, ugly hack to determine the example home without depending on the CWD this is needed for
@@ -83,10 +83,13 @@ public class ExternalPaths {
}
Path base = file.toAbsolutePath();
- while (!Files.exists(base.resolve("solr/test-framework/build.gradle")) && null != base) {
+ while (!Files.exists(base.resolve("test-framework/build.gradle"))) {
base = base.getParent();
+ if (base == null) {
+ return null;
+ }
}
- return (null == base) ? null : base.resolve("solr/").toAbsolutePath();
+ return base;
} catch (Exception e) {
// all bets are off
throw new SolrException(