Skip to content

Commit 36fd82f

Browse files
committed
Defensively resolve JarFile from JarURLConnection
Closes gh-34216
1 parent 0f26f42 commit 36fd82f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,17 @@ protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource,
834834

835835
if (con instanceof JarURLConnection jarCon) {
836836
// Should usually be the case for traditional JAR files.
837-
jarFile = jarCon.getJarFile();
838-
jarFileUrl = jarCon.getJarFileURL().toExternalForm();
839-
JarEntry jarEntry = jarCon.getJarEntry();
840-
rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
841-
closeJarFile = !jarCon.getUseCaches();
837+
try {
838+
jarFile = jarCon.getJarFile();
839+
jarFileUrl = jarCon.getJarFileURL().toExternalForm();
840+
JarEntry jarEntry = jarCon.getJarEntry();
841+
rootEntryPath = (jarEntry != null ? jarEntry.getName() : "");
842+
closeJarFile = !jarCon.getUseCaches();
843+
}
844+
catch (FileNotFoundException ex) {
845+
// Happens in case of cached root directory without specific subdirectory present.
846+
return Collections.emptySet();
847+
}
842848
}
843849
else {
844850
// No JarURLConnection -> need to resort to URL file parsing.

0 commit comments

Comments
 (0)