Skip to content

Commit c14f5fb

Browse files
committed
Polish "Fix handling of spaces in container's document root"
Closes gh-10706
1 parent 8031a1b commit c14f5fb

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.File;
2020
import java.io.IOException;
2121
import java.net.JarURLConnection;
22-
import java.net.URISyntaxException;
2322
import java.net.URL;
2423
import java.net.URLClassLoader;
2524
import java.net.URLConnection;
@@ -88,7 +87,7 @@ else if (this.logger.isDebugEnabled()) {
8887
}
8988

9089
private File getExplodedWarFileDocumentRoot() {
91-
return getExplodedWarFileDocumentRoot(getCodeSourceArchive(getCodeSource()));
90+
return getExplodedWarFileDocumentRoot(getCodeSourceArchive());
9291
}
9392

9493
protected List<URL> getUrlsOfJarsWithMetaInfResources() {
@@ -173,7 +172,7 @@ private File getWarFileDocumentRoot() {
173172
}
174173

175174
private File getArchiveFileDocumentRoot(String extension) {
176-
File file = getCodeSourceArchive(getCodeSource());
175+
File file = getCodeSourceArchive();
177176
if (this.logger.isDebugEnabled()) {
178177
this.logger.debug("Code archive: " + file);
179178
}
@@ -194,6 +193,10 @@ private File getCommonDocumentRoot() {
194193
return null;
195194
}
196195

196+
private File getCodeSourceArchive() {
197+
return getCodeSourceArchive(getClass().getProtectionDomain().getCodeSource());
198+
}
199+
197200
File getCodeSourceArchive(CodeSource codeSource) {
198201
try {
199202
URL location = (codeSource == null ? null : codeSource.getLocation());
@@ -213,16 +216,9 @@ File getCodeSourceArchive(CodeSource codeSource) {
213216
}
214217
return new File(path);
215218
}
216-
catch (IOException ex) {
219+
catch (Exception ex) {
217220
return null;
218221
}
219-
catch (URISyntaxException e) {
220-
return null;
221-
}
222-
}
223-
224-
private CodeSource getCodeSource() {
225-
return getClass().getProtectionDomain().getCodeSource();
226222
}
227223

228224
protected final File getValidSessionStoreDir() {

spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,16 +678,18 @@ public void cannotReadClassPathFiles() throws Exception {
678678
@Test
679679
public void codeSourceArchivePath() throws Exception {
680680
AbstractEmbeddedServletContainerFactory factory = getFactory();
681-
final CodeSource codeSource = new CodeSource(new URL("file", "", "/some/test/path/"), (Certificate[]) null);
682-
final File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
681+
CodeSource codeSource = new CodeSource(new URL("file", "", "/some/test/path/"),
682+
(Certificate[]) null);
683+
File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
683684
assertThat(codeSourceArchive).isEqualTo(new File("/some/test/path/"));
684685
}
685686

686687
@Test
687688
public void codeSourceArchivePathContainingSpaces() throws Exception {
688689
AbstractEmbeddedServletContainerFactory factory = getFactory();
689-
final CodeSource codeSource = new CodeSource(new URL("file", "", "/test/path/with%20space/"), (Certificate[]) null);
690-
final File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
690+
CodeSource codeSource = new CodeSource(
691+
new URL("file", "", "/test/path/with%20space/"), (Certificate[]) null);
692+
File codeSourceArchive = factory.getCodeSourceArchive(codeSource);
691693
assertThat(codeSourceArchive).isEqualTo(new File("/test/path/with space/"));
692694
}
693695

0 commit comments

Comments
 (0)