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

UndertowServletWebServerFactory does not configure a temporary directory #17778

Closed
wants to merge 1 commit into from
Closed

Conversation

Roiocam
Copy link
Contributor

@Roiocam Roiocam commented Aug 4, 2019

Description

I am using Spring Boot undertow construct upload file class, the configuration of the spring.servlet.multipart.location attributes, when the attribute value and the current environment is not configured at the same time, the undertow ManagedServlet setupMultipart method to obtain the servletContext.getDeployment().getDeploymentInfo().getTempPath() returns value. But this method doesn't seem to return the correct value. So the program throw the NPE .

Steps to Reproduce:

In Windows, I use spring.servlet.multipart.location=/opt/jar-application-dir
And then io.undertow.servlet.core.ManagedServlet Line 75 , will return false then in line 78 will throw the NullPointException. The reason is field tempDir was null.

In Linux, I use spring.servlet.multipart.location=C://jar-application-dir and then io.undertow.servlet.core.ManagedServlet Line 75 , will return false then in line 78 will throw the NullPointException. The reason is field tempDir was null.

Seem like the method Path.isAbsolute() can not recognize diffrent OS file system. and then UndertowServletWebServerFactory.createDeploymentManager() didn't init the field tempDir

This is exception stacktrace :

[restartedMain] ERROR org.springframework.boot.SpringApplication.reportFailure:858 - Application run failed
org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: java.lang.NullPointerException
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:157)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.**************Application.main(*****Application.java:22)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
	at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:252)
	at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.createDeploymentManager(UndertowServletWebServerFactory.java:284)
	at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory.getWebServer(UndertowServletWebServerFactory.java:208)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:181)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:154)
	... 13 common frames omitted
Caused by: java.lang.NullPointerException: null
	at io.undertow.servlet.core.ManagedServlet.setupMultipart(ManagedServlet.java:107)
	at io.undertow.servlet.spec.ServletRegistrationImpl.setMultipartConfig(ServletRegistrationImpl.java:117)
	at org.springframework.boot.web.servlet.ServletRegistrationBean.configure(ServletRegistrationBean.java:201)
	at org.springframework.boot.web.servlet.ServletRegistrationBean.configure(ServletRegistrationBean.java:51)
	at org.springframework.boot.web.servlet.DynamicRegistrationBean.register(DynamicRegistrationBean.java:115)
	at org.springframework.boot.web.servlet.RegistrationBean.onStartup(RegistrationBean.java:54)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:235)
	at org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory$Initializer.onStartup(UndertowServletWebServerFactory.java:616)
	at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:203)
	at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:185)
	at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)
	at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
	at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:250)
	... 17 common frames omitted

Fix :

First of all, i think the issue will be 'Undertow' cecause the exception was throw by Undertow Project object. But i trace the running stack,seem like UndertowServletWebServerFactory create an object but didn't giving a default value.So i push this commit , hope it's helpful.

@pivotal-issuemaster
Copy link

@Roiocam Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@Roiocam Thank you for signing the Contributor License Agreement!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 4, 2019
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 4, 2019
@philwebb philwebb added this to the 2.1.x milestone Aug 4, 2019
@mbhave
Copy link
Contributor

mbhave commented Aug 5, 2019

@Roiocam Would it be possible to add a test case for this?

@Roiocam
Copy link
Contributor Author

Roiocam commented Aug 7, 2019

@Roiocam Would it be possible to add a test case for this?

@mbhave it's complicated to make a JUint case for this bug. But i make a minimal application to reproduce this. See more detail In header block comment at the top of NpeDemoApplication.java
https://github.com/Roiocam/npe-demo

@snicoll snicoll self-assigned this Aug 8, 2019
@snicoll snicoll changed the title Fix NPE while setting up temporary directory UndertowServletWebServerFactory does not configure a temporary directory Aug 8, 2019
snicoll pushed a commit that referenced this pull request Aug 8, 2019
snicoll added a commit that referenced this pull request Aug 8, 2019
@snicoll snicoll closed this in c04454d Aug 8, 2019
@snicoll snicoll modified the milestones: 2.1.x, 2.1.8 Aug 8, 2019
@snicoll
Copy link
Member

snicoll commented Aug 8, 2019

@Roiocam thank you for making your first contribution to Spring Boot. They are indeed a couple of cases where Undertow expects the temporary directory to be set as a fallback option, the lack of a valid multipart location being one of them.

Turns out we have an infrastructure to create a temporary directory for the container so I've polished your contribution and used that. I've also added a test (agree it wasn't easy to setup so something we should probably improve).

@Roiocam
Copy link
Contributor Author

Roiocam commented Aug 9, 2019

It's great to see that my opinion was helpfully, I've seen how good it isthe change from you about the commit. It's seem that i should be more familiar with the project.

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

Successfully merging this pull request may close these issues.

None yet

6 participants