Ignore null Locale in MockHttpServletResponse

Prior to this commit, calls to setLocale() MockHttpServletResponse
would result in a NullPointerException if the supplied Locale was null.

Although the Javadoc for setLocale(Locale) and addHeader(String, String)
in javax.servlet.ServletResponse does not specify how a null
Locale should be handled, both Tomcat and Jetty simply ignore a null
value.

This commit therefore updates MockHttpServletResponse to silently
ignore a null Locale passed to setLocale().

Closes gh-26493
This commit is contained in:
Sam Brannen
2021-02-02 11:13:10 +01:00
parent 3b4a3431d4
commit c19b2851f1
3 changed files with 13 additions and 0 deletions

View File

@@ -85,6 +85,13 @@ class MockHttpServletResponseTests {
assertThat(response.containsHeader(headerName)).isFalse();
}
@Test // gh-26493
void setLocaleWithNullValue() {
assertThat(response.getLocale()).isEqualTo(Locale.getDefault());
response.setLocale(null);
assertThat(response.getLocale()).isEqualTo(Locale.getDefault());
}
@Test
void setContentType() {
String contentType = "test/plain";