Fix WebFlux default error view for null exception messages
This commit prevents NullPointerExceptions when the default HTML error view is being rendered with a `null` message. Fixes gh-11677
This commit is contained in:
parent
0b81f78a2a
commit
247b7f0842
|
@ -195,9 +195,13 @@ public abstract class AbstractErrorWebExceptionHandler
|
|||
.append(HtmlUtils.htmlEscape(error.get("error").toString()))
|
||||
.append(", status=")
|
||||
.append(HtmlUtils.htmlEscape(error.get("status").toString()))
|
||||
.append(").</div>").append("<div>")
|
||||
.append(HtmlUtils.htmlEscape(error.get("message").toString()))
|
||||
.append("</div>").append("</body></html>");
|
||||
.append(").</div>");
|
||||
if (error.get("message") != null) {
|
||||
builder.append("<div>")
|
||||
.append(HtmlUtils.htmlEscape(error.get("message").toString()))
|
||||
.append("</div>");
|
||||
}
|
||||
builder.append("</body></html>");
|
||||
return responseBody.syncBody(builder.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -240,6 +240,23 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
|||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionWithNullMessage() throws Exception {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.mustache.prefix=classpath:/unknown/")
|
||||
.run((context) -> {
|
||||
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
||||
.build();
|
||||
String body = client.get().uri("/notfound").accept(MediaType.TEXT_HTML)
|
||||
.exchange().expectStatus()
|
||||
.isEqualTo(HttpStatus.NOT_FOUND).expectHeader()
|
||||
.contentType(MediaType.TEXT_HTML).expectBody(String.class)
|
||||
.returnResult().getResponseBody();
|
||||
assertThat(body).contains("Whitelabel Error Page")
|
||||
.contains("type=Not Found, status=404");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseCommitted() throws Exception {
|
||||
this.contextRunner.run((context) -> {
|
||||
|
|
Loading…
Reference in New Issue