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

@@ -344,6 +344,9 @@ public class MockHttpServletResponse implements HttpServletResponse {
@Override
public void setLocale(Locale locale) {
if (locale == null) {
return;
}
this.locale = locale;
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, locale.toLanguageTag(), true);
}