diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java index 0b1f4929965..a6248141fec 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java @@ -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 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) { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java index fbbff0255f4..015798254b8 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java @@ -74,6 +74,14 @@ public class StaticResourceJarsTests { assertThat(staticResourceJarUrls).hasSize(0); } + @Test + public void uncPathsAreTolerated() throws Exception { + File jarFile = createResourcesJar("test-resources.jar"); + List 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");