I've developed a Solr plugin and tested it using Solr's Test Framework. I'm trying to upgrade my plugin from Solr 4.6 to Solr 4.10 by replacing the old Solr 4.6 jars with the newer 4.10 jars that my plugin depends upon. The upgrade caused my tests to fail with the following RuntimeException
:
Resource was found on classpath, but cannot be resolved to a normal file (maybe it is part of a JAR file): solr/collection1
The resource solr/collection1
is a directory located on the file system that contains, among other things, the conf/solrconfig.xml
and conf/schema.xml
configuration files which the test framework requires.
I have taken a look at the source code of Solr, namely at SolrTestCaseJ4.java, where the error originates, and that file contains the following getFile
method:
public static File getFile(String name) {
final URL url =
Thread.currentThread().getContextClassLoader().getResource(name);
try {
return new File(url.toURI());
} catch (Exception e) {
throw new RuntimeException("Resource was found on classpath, but cannot be resolved to a normal file (maybe it is part of a JAR file): " + name);
}
...
}
The getFile
method receives a string name="solr/collection1"
as a parameter and then it actually corrupts it by setting the URL url
local variable to the following illegal path:
jar:file:/C:/solr-4.10.3/solr-4.10.3/dist/solr-uima-4.10.3.jar!/solr/collection1
Then, the call to the constructor of File
with url.toURI()
as a parameter (new File(url.toURI())
) causes the throwing of an Illegal Argument Exception saying the URI is not hierarchical. This is what's leading to the throwing of the above Runtime Exception.
The first line of the getFile
method, the one setting the URL url
local variable, did not exist in Solr 4.6. In Solr 4.6 the getFile
method initialized the new File
with the given name="solr/collection1"
parameter:
File file = new File(name); //name = "solr/collection1"
This is the reason why that error did not exist in Solr 4.6. Why does the test framework in Solr 4.10 generate that odd URL
? How can I force it to set the URL
properly so it can execute my tests without encountering that Runtime Exception?