Skip to content

Commit 667ccda

Browse files
committed
Simplify temp directory creation and improve diagnostics
Closes gh-23622
1 parent ce70e7d commit 667ccda

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/web/SpringBootMockServletContext.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
import java.io.IOException;
2121
import java.net.MalformedURLException;
2222
import java.net.URL;
23+
import java.nio.file.Files;
2324

2425
import org.springframework.core.io.FileSystemResourceLoader;
2526
import org.springframework.core.io.Resource;
@@ -93,9 +94,7 @@ public URL getResource(String path) throws MalformedURLException {
9394
try {
9495
if (this.emptyRootFolder == null) {
9596
synchronized (this) {
96-
File tempFolder = File.createTempFile("spr", "servlet");
97-
tempFolder.delete();
98-
tempFolder.mkdirs();
97+
File tempFolder = Files.createTempDirectory("spr-servlet").toFile();
9998
tempFolder.deleteOnExit();
10099
this.emptyRootFolder = tempFolder;
101100
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/AbstractConfigurableWebServerFactory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020
import java.io.IOException;
2121
import java.net.InetAddress;
22+
import java.nio.file.Files;
2223
import java.util.Arrays;
2324
import java.util.LinkedHashSet;
2425
import java.util.Set;
@@ -169,9 +170,7 @@ public void setServerHeader(String serverHeader) {
169170
*/
170171
protected final File createTempDir(String prefix) {
171172
try {
172-
File tempDir = File.createTempFile(prefix + ".", "." + getPort());
173-
tempDir.delete();
174-
tempDir.mkdir();
173+
File tempDir = Files.createTempDirectory(prefix + "." + getPort() + ".").toFile();
175174
tempDir.deleteOnExit();
176175
return tempDir;
177176
}

0 commit comments

Comments
 (0)