From 1fbd43bdf06876728ac0279de5c1dd33fcad1c32 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 15 Apr 2016 17:11:41 +0100 Subject: [PATCH 1/2] Tolerate jar files with no manifest in ChangeableUrls Closes gh-5704 --- .../boot/devtools/restart/ChangeableUrls.java | 26 +++++++++++-------- .../devtools/restart/ChangeableUrlsTests.java | 9 ++++++- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java index 927753770c..432086e300 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java @@ -119,19 +119,23 @@ final class ChangeableUrls implements Iterable { } private static List getUrlsFromClassPathAttribute(URL base, Manifest manifest) { - List urls = new ArrayList(); + if (manifest == null) { + return Collections.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.emptyList(); + } + List urls = new ArrayList(); + 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; diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java index 117e2d67cc..9caf83dacd 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java @@ -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(); + } + } From b554894bb4346a4aac196f6cec1fe3229de96ef7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 15 Apr 2016 17:27:19 +0100 Subject: [PATCH 2/2] Polishing --- .../boot/devtools/restart/ChangeableUrlsTests.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java index 9caf83dacd..71c9def3f3 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java @@ -79,9 +79,11 @@ public class ChangeableUrlsTests { URL projectCore = makeUrl("project-core"); URL projectWeb = makeUrl("project-web"); File relative = this.temporaryFolder.newFolder(); - ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(new URLClassLoader( - new URL[] { makeJarFileWithUrlsInManifestClassPath(projectCore, - projectWeb, relative.getName() + "/"), makeJarFileWithNoManifest() })); + ChangeableUrls urls = ChangeableUrls + .fromUrlClassLoader(new URLClassLoader(new URL[] { + makeJarFileWithUrlsInManifestClassPath(projectCore, projectWeb, + relative.getName() + "/"), + makeJarFileWithNoManifest() })); assertThat(urls.toList(), contains(projectCore, projectWeb, relative.toURI().toURL())); }