Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Files.createTempDirectory(String, FileAttribute<?>...) for temporary directory creation #23622

Closed
rulerskbr99 opened this issue Oct 8, 2020 · 7 comments
Labels
type: task A general task
Milestone

Comments

@rulerskbr99
Copy link

rulerskbr99 commented Oct 8, 2020

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2020-10-08 23:35:36.770 ERROR 10216 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is **java.lang.IllegalArgumentException: The location [C:\Temp\tomcat.2991047597755146144.9000] specified for the base directory is not a directory**
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at info.inetsolv.CloudConfigServerSbApplication.main(CloudConfigServerSbApplication.java:13) [classes/:na]
Caused by: java.lang.IllegalArgumentException: The location [C:\Temp\tomcat.2991047597755146144.9000] specified for the base directory is not a directory
	at org.apache.catalina.startup.Tomcat.initBaseDir(Tomcat.java:868) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.startup.Tomcat.getServer(Tomcat.java:657) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.apache.catalina.startup.Tomcat.getService(Tomcat.java:589) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
	at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:182) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:178) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158) ~[spring-boot-2.3.3.RELEASE.jar:2.3.3.RELEASE]
	... 9 common frames omitted
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 8, 2020
@wilkinsona
Copy link
Member

Does C:\Temp exist on your machine and does the user running your application have permission to create a sub-directory in that location?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Oct 8, 2020
@rulerskbr99
Copy link
Author

Does C:\Temp exist on your machine and does the user running your application have permission to create a sub-directory in that location?

Yes i have c:\Temp directory and only 1 user exist (i.e Admin)

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 9, 2020
@wilkinsona
Copy link
Member

Thanks. Unfortunately, I cannot explain the failure in that case. The code that creates the directory is the following:

protected final File createTempDir(String prefix) {
try {
File tempDir = File.createTempFile(prefix + ".", "." + getPort());
tempDir.delete();
tempDir.mkdir();
tempDir.deleteOnExit();
return tempDir;
}
catch (IOException ex) {
throw new WebServerException(
"Unable to create tempDir. java.io.tmpdir is set to " + System.getProperty("java.io.tmpdir"), ex);
}
}

We aren't checking the return value of delete() or mkdir() so I had wondered if one of those calls was failing. However, looking more closely, File.createTempFile would have failed in that case and thrown an IOException.

I believe the problem you are seeing is specific to your environment as we haven't had a report from anyone else or seen this failure on our Windows CI. Perhaps you have a virus scanner that scans the newly created file and prevents it from being deleted?

Regardless, I think we could improve the diagnostics here while also simplifying the code by switching to java.nio.file.Files.createTempDirectory(String, FileAttribute<?>...). We can use this issue to do that.

@wilkinsona wilkinsona added type: task A general task and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Oct 9, 2020
@wilkinsona wilkinsona added this to the 2.2.x milestone Oct 9, 2020
@wilkinsona wilkinsona changed the title The location specified for the base directory is not a directory Use Files.createTempDirectory(String, FileAttribute<?>...) for temporary directory creation Oct 9, 2020
@kaushikrk
Copy link

is there any workaround for this issue? I also face this issue.

@wilkinsona
Copy link
Member

@kaushikrk You can set server.tomcat.basedir to a location of your choosing to avoid the creation of the temporary directory.

@rulerskbr99
Copy link
Author

Do i need to set any environment variable for this issue like TEMP folder....?

@wilkinsona
Copy link
Member

The location of temporary files is determined by the java.io.tmpdir system property. This answer on Stack Overflow has some useful information on the system property's default value on Windows and the environment variables that affect it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

4 participants