PathMatchingResourcePatternResolver skips invalid jar classpath entries

Issue: SPR-12928
This commit is contained in:
Juergen Hoeller 2015-04-24 17:40:13 +02:00
parent 86fd0afbf2
commit 49f3046f66
1 changed files with 20 additions and 11 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,6 +32,7 @@ import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.zip.ZipException;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -517,6 +518,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
// being arbitrary as long as following the entry format. // being arbitrary as long as following the entry format.
// We'll also handle paths with and without leading "file:" prefix. // We'll also handle paths with and without leading "file:" prefix.
String urlFile = rootDirResource.getURL().getFile(); String urlFile = rootDirResource.getURL().getFile();
try {
int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR); int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
if (separatorIndex != -1) { if (separatorIndex != -1) {
jarFileUrl = urlFile.substring(0, separatorIndex); jarFileUrl = urlFile.substring(0, separatorIndex);
@ -530,6 +532,13 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
} }
newJarFile = true; newJarFile = true;
} }
catch (ZipException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping invalid jar classpath entry [" + urlFile + "]");
}
return Collections.emptySet();
}
}
try { try {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {