Skip to content

Commit 1fbd43b

Browse files
committed
Tolerate jar files with no manifest in ChangeableUrls
Closes spring-projectsgh-5704
1 parent a2f482b commit 1fbd43b

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/ChangeableUrls.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,23 @@ private static JarFile getJarFileIfPossible(URL url) {
119119
}
120120

121121
private static List<URL> getUrlsFromClassPathAttribute(URL base, Manifest manifest) {
122-
List<URL> urls = new ArrayList<URL>();
122+
if (manifest == null) {
123+
return Collections.<URL>emptyList();
124+
}
123125
String classPathAttribute = manifest.getMainAttributes()
124126
.getValue(Attributes.Name.CLASS_PATH);
125-
if (StringUtils.hasText(classPathAttribute)) {
126-
for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute,
127-
" ")) {
128-
try {
129-
urls.add(new URL(base, entry));
130-
}
131-
catch (MalformedURLException ex) {
132-
throw new IllegalStateException(
133-
"Class-Path attribute contains malformed URL", ex);
134-
}
127+
if (!StringUtils.hasText(classPathAttribute)) {
128+
return Collections.<URL>emptyList();
129+
}
130+
List<URL> urls = new ArrayList<URL>();
131+
for (String entry : StringUtils.delimitedListToStringArray(classPathAttribute,
132+
" ")) {
133+
try {
134+
urls.add(new URL(base, entry));
135+
}
136+
catch (MalformedURLException ex) {
137+
throw new IllegalStateException(
138+
"Class-Path attribute contains malformed URL", ex);
135139
}
136140
}
137141
return urls;

spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/ChangeableUrlsTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.jar.Attributes;
2525
import java.util.jar.JarOutputStream;
2626
import java.util.jar.Manifest;
27+
import java.util.zip.ZipOutputStream;
2728

2829
import org.junit.Rule;
2930
import org.junit.Test;
@@ -80,7 +81,7 @@ public void urlsFromJarClassPathAreConsidered() throws Exception {
8081
File relative = this.temporaryFolder.newFolder();
8182
ChangeableUrls urls = ChangeableUrls.fromUrlClassLoader(new URLClassLoader(
8283
new URL[] { makeJarFileWithUrlsInManifestClassPath(projectCore,
83-
projectWeb, relative.getName() + "/") }));
84+
projectWeb, relative.getName() + "/"), makeJarFileWithNoManifest() }));
8485
assertThat(urls.toList(),
8586
contains(projectCore, projectWeb, relative.toURI().toURL()));
8687
}
@@ -105,4 +106,10 @@ private URL makeJarFileWithUrlsInManifestClassPath(Object... urls) throws Except
105106
return classpathJar.toURI().toURL();
106107
}
107108

109+
private URL makeJarFileWithNoManifest() throws Exception {
110+
File classpathJar = this.temporaryFolder.newFile("no-manifest.jar");
111+
new ZipOutputStream(new FileOutputStream(classpathJar)).close();
112+
return classpathJar.toURI().toURL();
113+
}
114+
108115
}

0 commit comments

Comments
 (0)