Skip to content

Commit df70c42

Browse files
committed
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
1 parent e54b7d0 commit df70c42

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.net.URL;
2626
import java.net.URLClassLoader;
2727
import java.net.URLConnection;
28+
import java.nio.file.InvalidPathException;
2829
import java.util.ArrayList;
2930
import java.util.List;
3031
import java.util.jar.JarFile;
@@ -124,7 +125,7 @@ private boolean isResourcesJar(File file) {
124125
try {
125126
return isResourcesJar(new JarFile(file));
126127
}
127-
catch (IOException ex) {
128+
catch (IOException | InvalidPathException ex) {
128129
return false;
129130
}
130131
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/StaticResourceJarsTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ public void uncPathsAreTolerated() throws Exception {
7878
assertThat(staticResourceJarUrls).hasSize(1);
7979
}
8080

81+
@Test
82+
public void ignoreWildcardUrls() throws Exception {
83+
File jarFile = createResourcesJar("test-resources.jar");
84+
URL folderUrl = jarFile.getParentFile().toURI().toURL();
85+
URL wildcardUrl = new URL(folderUrl.toString() + "*.jar");
86+
List<URL> staticResourceJarUrls = new StaticResourceJars().getUrlsFrom(wildcardUrl);
87+
assertThat(staticResourceJarUrls).isEmpty();
88+
}
89+
8190
private File createResourcesJar(String name) throws IOException {
8291
return createJar(name, (output) -> {
8392
JarEntry jarEntry = new JarEntry("META-INF/resources");

0 commit comments

Comments
 (0)