提交 9334fabe 编写于 作者: B Brian Clozel

Don't throw NPE when serving webjar directories

Prior to this change, serving resources with ResourceHttpRequestHandler
could result in NPE when requesting an existing folder located in a JAR.

This commit swallows those exceptions, as it is not possible to foresee
those cases without reading the actual resource. This result in a HTTP
200 response with a zero Content-Length instead of a HTTP 500 internal
exception.

Issue: SPR-13620
上级 323fa851
......@@ -460,6 +460,9 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
try {
StreamUtils.copy(in, response.getOutputStream());
}
catch (NullPointerException ex) {
// ignore, see SPR-13620
}
finally {
try {
in.close();
......
......@@ -478,6 +478,20 @@ public class ResourceHttpRequestHandlerTests {
assertEquals(0, this.response.getContentLength());
}
// SPR-13620
@Test
public void writeContentInputStreamThrowingNullPointerException() throws Exception {
Resource resource = mock(Resource.class);
InputStream in = mock(InputStream.class);
given(resource.getInputStream()).willReturn(in);
given(in.read(any())).willThrow(NullPointerException.class);
this.handler.writeContent(this.response, resource);
assertEquals(200, this.response.getStatus());
assertEquals(0, this.response.getContentLength());
}
private long dateHeaderAsLong(String responseHeaderName) throws Exception {
return dateFormat.parse(this.response.getHeader(responseHeaderName)).getTime();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册