Apache Lucene open-source search software
SOLR-5764: Make error message of SolrTestCaseJ4.getFile() more readable.
Uwe Schindler94db09410fd4
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex f738925195c..c3fab2e0e5d 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -24,6 +24,8 @@ import java.io.IOException;import java.io.Reader;import java.io.StringReader;import java.io.StringWriter;+import java.net.URISyntaxException;+import java.net.URL;import java.util.ArrayList;import java.util.Arrays;import java.util.Comparator;@@ -1663,16 +1665,19 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {* {@link Class#getResourceAsStream} using {@code this.getClass()}.*/public static File getFile(String name) {- try {- File file = new File(name);- if (!file.exists()) {- file = new File(Thread.currentThread().getContextClassLoader().getResource(name).toURI());+ final URL url = Thread.currentThread().getContextClassLoader().getResource(name.replace(File.separatorChar, '/'));+ if (url != null) {+ try {+ return new File(url.toURI());+ } catch (URISyntaxException use) {+ // ignore + fall-through}+ }+ final File file = new File(name);+ if (file.exists()) {return file;- } catch (Exception e) {- /* more friendly than NPE */- throw new RuntimeException("Cannot find resource: " + new File(name).getAbsolutePath());}+ throw new RuntimeException("Cannot find resource in classpath or in file-system (relative to CWD): " + name);}public static String TEST_HOME() {