Skip to content

Commit 6a7aab0

Browse files
committed
PathMatchingResourcePatternResolver skips invalid jar classpath entries
Issue: SPR-12928 (cherry picked from commit 49f3046)
1 parent e95a7a4 commit 6a7aab0

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import java.util.Set;
3333
import java.util.jar.JarEntry;
3434
import java.util.jar.JarFile;
35+
import java.util.zip.ZipException;
3536

3637
import org.apache.commons.logging.Log;
3738
import org.apache.commons.logging.LogFactory;
@@ -517,18 +518,26 @@ protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource,
517518
// being arbitrary as long as following the entry format.
518519
// We'll also handle paths with and without leading "file:" prefix.
519520
String urlFile = rootDirResource.getURL().getFile();
520-
int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
521-
if (separatorIndex != -1) {
522-
jarFileUrl = urlFile.substring(0, separatorIndex);
523-
rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
524-
jarFile = getJarFile(jarFileUrl);
521+
try {
522+
int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
523+
if (separatorIndex != -1) {
524+
jarFileUrl = urlFile.substring(0, separatorIndex);
525+
rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
526+
jarFile = getJarFile(jarFileUrl);
527+
}
528+
else {
529+
jarFile = new JarFile(urlFile);
530+
jarFileUrl = urlFile;
531+
rootEntryPath = "";
532+
}
533+
newJarFile = true;
525534
}
526-
else {
527-
jarFile = new JarFile(urlFile);
528-
jarFileUrl = urlFile;
529-
rootEntryPath = "";
535+
catch (ZipException ex) {
536+
if (logger.isDebugEnabled()) {
537+
logger.debug("Skipping invalid jar classpath entry [" + urlFile + "]");
538+
}
539+
return Collections.emptySet();
530540
}
531-
newJarFile = true;
532541
}
533542

534543
try {

0 commit comments

Comments
 (0)