From b29723623b33f1ce8fbffec19e4c4dec91bf2da7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 17 Nov 2020 14:45:45 +0100 Subject: [PATCH] Encode hash symbol in jar file path (for compatibility with JDK 11+) Closes gh-26104 --- .../core/io/support/PathMatchingResourcePatternResolver.java | 3 +++ 1 file changed, 3 insertions(+) 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 39d79fb2af..69cd661348 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 @@ -432,6 +432,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol // Possibly "c:" drive prefix on Windows, to be upper-cased for proper duplicate detection filePath = StringUtils.capitalize(filePath); } + // # can appear in directories/filenames, java.net.URL should not treat it as a fragment + filePath = StringUtils.replace(filePath, "#", "%23"); + // Build URL that points to the root of the jar file UrlResource jarResource = new UrlResource(ResourceUtils.JAR_URL_PREFIX + ResourceUtils.FILE_URL_PREFIX + filePath + ResourceUtils.JAR_URL_SEPARATOR); // Potentially overlapping with URLClassLoader.getURLs() result above!