From df70c42f982f0088b83cb4187f2dedd41480e601 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 5 May 2020 12:06:40 -0700 Subject: [PATCH] Allow classpath wildcards with Java 11 or above Update `StaticResourceJars` to catch both `IOException` and `InvalidPathException` when checking URLs. Prior to this commit only `IOException` was caught which worked on Java 8 but not Java 11 or above. Fixes gh-21312 --- .../boot/web/servlet/server/StaticResourceJars.java | 3 ++- .../boot/web/servlet/server/StaticResourceJarsTests.java | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 0bd18af36e3..a96fcce0e28 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 @@ -25,6 +25,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; import java.net.URLConnection; +import java.nio.file.InvalidPathException; import java.util.ArrayList; import java.util.List; import java.util.jar.JarFile; @@ -124,7 +125,7 @@ class StaticResourceJars { try { return isResourcesJar(new JarFile(file)); } - catch (IOException ex) { + catch (IOException | InvalidPathException ex) { return false; } } 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 f63ba3e1185..f4d20b32894 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 @@ -78,6 +78,15 @@ public class StaticResourceJarsTests { assertThat(staticResourceJarUrls).hasSize(1); } + @Test + public void ignoreWildcardUrls() throws Exception { + File jarFile = createResourcesJar("test-resources.jar"); + URL folderUrl = jarFile.getParentFile().toURI().toURL(); + URL wildcardUrl = new URL(folderUrl.toString() + "*.jar"); + List staticResourceJarUrls = new StaticResourceJars().getUrlsFrom(wildcardUrl); + assertThat(staticResourceJarUrls).isEmpty(); + } + private File createResourcesJar(String name) throws IOException { return createJar(name, (output) -> { JarEntry jarEntry = new JarEntry("META-INF/resources");