From 36fd82f32f03cfcded746522a501bcc1c8b24fa2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sun, 12 Jan 2025 18:07:09 +0100 Subject: [PATCH] Defensively resolve JarFile from JarURLConnection Closes gh-34216 --- .../PathMatchingResourcePatternResolver.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index f8d52657a0..a6899040fd 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -834,11 +834,17 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol if (con instanceof JarURLConnection jarCon) { // Should usually be the case for traditional JAR files. - jarFile = jarCon.getJarFile(); - jarFileUrl = jarCon.getJarFileURL().toExternalForm(); - JarEntry jarEntry = jarCon.getJarEntry(); - rootEntryPath = (jarEntry != null ? jarEntry.getName() : ""); - closeJarFile = !jarCon.getUseCaches(); + try { + jarFile = jarCon.getJarFile(); + jarFileUrl = jarCon.getJarFileURL().toExternalForm(); + JarEntry jarEntry = jarCon.getJarEntry(); + rootEntryPath = (jarEntry != null ? jarEntry.getName() : ""); + closeJarFile = !jarCon.getUseCaches(); + } + catch (FileNotFoundException ex) { + // Happens in case of cached root directory without specific subdirectory present. + return Collections.emptySet(); + } } else { // No JarURLConnection -> need to resort to URL file parsing.