Tolerate jar files with no manifest in ChangeableUrls

Closes gh-5704
pull/5808/merge
Andy Wilkinson 9 years ago
parent a2f482b7f3
commit 1fbd43bdf0

@ -119,19 +119,23 @@ final class ChangeableUrls implements Iterable<URL> {
}
private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manifest) {
List<URL> urls = new ArrayList<URL>();
if (manifest == null) {
return Collections.<URL>emptyList();
}
String classPathAttribute = manifest.getMainAttributes()
.getValue(Attributes.Name.CLASS_PATH);
if (StringUtils.hasText(classPathAttribute)) {
for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute,
" ")) {
try {
urls.add(new URL(base, entry));
}
catch (MalformedURLException ex) {
throw new IllegalStateException(
"Class-Path attribute contains malformed URL", ex);
}
if (!StringUtils.hasText(classPathAttribute)) {
return Collections.<URL>emptyList();
}
List<URL> urls = new ArrayList<URL>();
for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute,
" ")) {
try {
urls.add(new URL(base, entry));
}
catch (MalformedURLException ex) {
throw new IllegalStateException(
"Class-Path attribute contains malformed URL", ex);
}
}
return urls;

@ -24,6 +24,7 @@ import java.net.URLClassLoader;
import java.util.jar.Attributes;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import java.util.zip.ZipOutputStream;
import org.junit.Rule;
import org.junit.Test;
@ -80,7 +81,7 @@ public class ChangeableUrlsTests {
File relative = this.temporaryFolder.newFolder();
ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(new URLClassLoader(
new URL[] { makeJarFileWithUrlsInManifestClassPath(projectCore,
projectWeb, relative.getName() + "/") }));
projectWeb, relative.getName() + "/"), makeJarFileWithNoManifest() }));
assertThat(urls.toList(),
contains(projectCore, projectWeb, relative.toURI().toURL()));
}
@ -105,4 +106,10 @@ public class ChangeableUrlsTests {
return classpathJar.toURI().toURL();
}
private URL makeJarFileWithNoManifest() throws Exception {
File classpathJar = this.temporaryFolder.newFile("no-manifest.jar");
new ZipOutputStream(new FileOutputStream(classpathJar)).close();
return classpathJar.toURI().toURL();
}
}

Loading…
Cancel
Save