Skip to content

Commit 1da74ce

Browse files
dweissdsmiley
andauthored
SOLR-18092: fix solr-test-framework for 3rd party -- ExternalPaths NPE (#4225)
Co-authored-by: David Smiley <dsmiley@apache.org>
1 parent 6f15595 commit 1da74ce

3 files changed

Lines changed: 27 additions & 13 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
title: solr-test-framework isn't usable outside Solr, a 10.0 regression.
2+
type: fixed
3+
authors:
4+
- name: Dawid Weiss
5+
- name: David Smiley
6+
- name: Eric Pugh
7+
- name: hossman
8+
links:
9+
- name: SOLR-18092
10+
url: https://issues.apache.org/jira/browse/SOLR-18092
11+
12+

solr/test-framework/src/java/org/apache/solr/SolrTestCase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
2626
import com.carrotsearch.randomizedtesting.rules.TestRuleAdapter;
2727
import java.lang.invoke.MethodHandles;
28-
import java.nio.file.Files;
2928
import java.nio.file.Path;
3029
import java.util.List;
3130
import java.util.Objects;
@@ -130,7 +129,7 @@ public static void beforeSolrTestCase() {
130129
return;
131130
}
132131
final Path extPath = ExternalPaths.DEFAULT_CONFIGSET;
133-
if (Files.isReadable(extPath /* implies exists() */) && Files.isDirectory(extPath)) {
132+
if (extPath != null) {
134133
log.info(
135134
"Setting '{}' system property to test-framework derived value of '{}'",
136135
ConfigSetService.SOLR_CONFIGSET_DEFAULT_CONFDIR,

solr/test-framework/src/java/org/apache/solr/util/ExternalPaths.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,38 @@
3030
public class ExternalPaths {
3131

3232
/**
33-
* The main directory path for the solr source being built if it can be determined. If it can not
33+
* The main directory path for the solr source being built if it can be determined. If it cannot
3434
* be determined -- possibly because the current context is a client code base using the test
3535
* framework -- then this variable will be null.
3636
*
3737
* <p>Note that all other static paths available in this class are derived from the source home,
38-
* and if it is null, those paths will just be relative to 'null' and may not be meaningful.
38+
* and if it is null, those paths will be null as well.
3939
*/
40-
public static final Path SOURCE_HOME = determineSourceHome();
40+
public static final Path SOURCE_HOME = determineSourceHome(); // absolute
4141

4242
/**
4343
* @see #SOURCE_HOME
4444
*/
45-
public static Path WEBAPP_HOME = SOURCE_HOME.resolve("webapp/web").toAbsolutePath();
45+
public static Path WEBAPP_HOME = SOURCE_HOME == null ? null : SOURCE_HOME.resolve("webapp/web");
4646

4747
/**
4848
* @see #SOURCE_HOME
4949
*/
5050
public static Path DEFAULT_CONFIGSET =
51-
SOURCE_HOME.resolve("server/solr/configsets/_default/conf").toAbsolutePath();
51+
SOURCE_HOME == null ? null : SOURCE_HOME.resolve("server/solr/configsets/_default/conf");
5252

5353
/**
5454
* @see #SOURCE_HOME
5555
*/
5656
public static Path TECHPRODUCTS_CONFIGSET =
57-
SOURCE_HOME
58-
.resolve("server/solr/configsets/sample_techproducts_configs/conf")
59-
.toAbsolutePath();
57+
SOURCE_HOME == null
58+
? null
59+
: SOURCE_HOME.resolve("server/solr/configsets/sample_techproducts_configs/conf");
6060

6161
/**
6262
* @see #SOURCE_HOME
6363
*/
64-
public static Path SERVER_HOME = SOURCE_HOME.resolve("server/solr").toAbsolutePath();
64+
public static Path SERVER_HOME = SOURCE_HOME == null ? null : SOURCE_HOME.resolve("server/solr");
6565

6666
/**
6767
* Ugly, ugly hack to determine the example home without depending on the CWD this is needed for
@@ -83,10 +83,13 @@ static Path determineSourceHome() {
8383
}
8484

8585
Path base = file.toAbsolutePath();
86-
while (!Files.exists(base.resolve("solr/test-framework/build.gradle")) && null != base) {
86+
while (!Files.exists(base.resolve("test-framework/build.gradle"))) {
8787
base = base.getParent();
88+
if (base == null) {
89+
return null;
90+
}
8891
}
89-
return (null == base) ? null : base.resolve("solr/").toAbsolutePath();
92+
return base;
9093
} catch (Exception e) {
9194
// all bets are off
9295
throw new SolrException(

0 commit comments

Comments
 (0)