Skip to content

Commit f16d453

Browse files
committed
PathMatchingResourcePatternResolver converts manifest entries to absolute paths and tries all root URLs (any file extension) as jar file
Issue: SPR-14934 Issue: SPR-14936
1 parent 2b02935 commit f16d453

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,17 @@ protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource>
365365
if (classLoader instanceof URLClassLoader) {
366366
try {
367367
for (URL url : ((URLClassLoader) classLoader).getURLs()) {
368-
if (ResourceUtils.isJarFileURL(url)) {
369-
try {
370-
UrlResource jarResource = new UrlResource(
371-
ResourceUtils.JAR_URL_PREFIX + url.toString() + ResourceUtils.JAR_URL_SEPARATOR);
372-
if (jarResource.exists()) {
373-
result.add(jarResource);
374-
}
368+
try {
369+
UrlResource jarResource = new UrlResource(
370+
ResourceUtils.JAR_URL_PREFIX + url.toString() + ResourceUtils.JAR_URL_SEPARATOR);
371+
if (jarResource.exists()) {
372+
result.add(jarResource);
375373
}
376-
catch (MalformedURLException ex) {
377-
if (logger.isDebugEnabled()) {
378-
logger.debug("Cannot search for matching files underneath [" + url +
379-
"] because it cannot be converted to a valid 'jar:' URL: " + ex.getMessage());
380-
}
374+
}
375+
catch (MalformedURLException ex) {
376+
if (logger.isDebugEnabled()) {
377+
logger.debug("Cannot search for matching files underneath [" + url +
378+
"] because it cannot be converted to a valid 'jar:' URL: " + ex.getMessage());
381379
}
382380
}
383381
}
@@ -418,20 +416,20 @@ protected void addAllClassLoaderJarRoots(ClassLoader classLoader, Set<Resource>
418416
protected void addClassPathManifestEntries(Set<Resource> result) {
419417
try {
420418
String javaClassPathProperty = System.getProperty("java.class.path");
421-
for (String url : StringUtils.delimitedListToStringArray(
419+
for (String path : StringUtils.delimitedListToStringArray(
422420
javaClassPathProperty, System.getProperty("path.separator"))) {
423421
try {
424-
if (url.endsWith(ResourceUtils.JAR_FILE_EXTENSION)) {
425-
UrlResource jarResource = new UrlResource(ResourceUtils.JAR_URL_PREFIX +
426-
ResourceUtils.FILE_URL_PREFIX + url + ResourceUtils.JAR_URL_SEPARATOR);
427-
if (jarResource.exists()) {
428-
result.add(jarResource);
429-
}
422+
File file = new File(path);
423+
UrlResource jarResource = new UrlResource(ResourceUtils.JAR_URL_PREFIX +
424+
ResourceUtils.FILE_URL_PREFIX + file.getAbsolutePath() +
425+
ResourceUtils.JAR_URL_SEPARATOR);
426+
if (jarResource.exists()) {
427+
result.add(jarResource);
430428
}
431429
}
432430
catch (MalformedURLException ex) {
433431
if (logger.isDebugEnabled()) {
434-
logger.debug("Cannot search for matching files underneath [" + url +
432+
logger.debug("Cannot search for matching files underneath [" + path +
435433
"] because it cannot be converted to a valid 'jar:' URL: " + ex.getMessage());
436434
}
437435
}

0 commit comments

Comments
 (0)