Remove assumption that a file URI can be turned into a File

Closes gh-13493
This commit is contained in:
Andy Wilkinson 2018-06-21 12:40:48 +01:00
parent f2cc6e2ef2
commit fd125b4a4a
2 changed files with 20 additions and 3 deletions

View File

@ -78,15 +78,24 @@ class StaticResourceJars {
throw new IllegalStateException(
"Failed to create File from URL '" + url + "'");
}
catch (IllegalArgumentException ex) {
return null;
}
}
private void addUrl(List<URL> urls, URL url) {
try {
if ("file".equals(url.getProtocol())) {
addUrlFile(urls, url, toFile(url));
if (!"file".equals(url.getProtocol())) {
addUrlConnection(urls, url, url.openConnection());
}
else {
addUrlConnection(urls, url, url.openConnection());
File file = toFile(url);
if (file != null) {
addUrlFile(urls, url, file);
}
else {
addUrlConnection(urls, url, url.openConnection());
}
}
}
catch (IOException ex) {

View File

@ -74,6 +74,14 @@ public class StaticResourceJarsTests {
assertThat(staticResourceJarUrls).hasSize(0);
}
@Test
public void uncPathsAreTolerated() throws Exception {
File jarFile = createResourcesJar("test-resources.jar");
List<URL> staticResourceJarUrls = new StaticResourceJars().getUrlsFrom(
jarFile.toURI().toURL(), new URL("file://unc.example.com/test.jar"));
assertThat(staticResourceJarUrls).hasSize(1);
}
private File createResourcesJar(String name) throws IOException {
return createJar(name, (output) -> {
JarEntry jarEntry = new JarEntry("META-INF/resources");