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,18 +518,26 @@ 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();
int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR); try {
if (separatorIndex != -1) { int separatorIndex = urlFile.indexOf(ResourceUtils.JAR_URL_SEPARATOR);
jarFileUrl = urlFile.substring(0, separatorIndex); if (separatorIndex != -1) {
rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length()); jarFileUrl = urlFile.substring(0, separatorIndex);
jarFile = getJarFile(jarFileUrl); rootEntryPath = urlFile.substring(separatorIndex + ResourceUtils.JAR_URL_SEPARATOR.length());
jarFile = getJarFile(jarFileUrl);
}
else {
jarFile = new JarFile(urlFile);
jarFileUrl = urlFile;
rootEntryPath = "";
}
newJarFile = true;
} }
else { catch (ZipException ex) {
jarFile = new JarFile(urlFile); if (logger.isDebugEnabled()) {
jarFileUrl = urlFile; logger.debug("Skipping invalid jar classpath entry [" + urlFile + "]");
rootEntryPath = ""; }
return Collections.emptySet();
} }
newJarFile = true;
} }
try { try {