From 5b3f11c543cefabd4de3a1eb1f8b7ab38e394472 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 29 Jul 2021 14:47:31 +0200 Subject: [PATCH] Add @Nullable to setLocale in MockHttpServletResponse See gh-26493 --- .../springframework/mock/web/MockHttpServletResponse.java | 5 ++++- .../web/testfixture/servlet/MockHttpServletResponse.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java index a314079379..52a7ab354f 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -358,7 +358,10 @@ public class MockHttpServletResponse implements HttpServletResponse { } @Override - public void setLocale(Locale locale) { + public void setLocale(@Nullable Locale locale) { + // Although the Javadoc for javax.servlet.ServletResponse.setLocale(Locale) does not + // state how a null value for the supplied Locale should be handled, both Tomcat and + // Jetty simply ignore a null value. So we do the same here. if (locale == null) { return; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java index fc294fe2b6..7418a28716 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java @@ -358,7 +358,10 @@ public class MockHttpServletResponse implements HttpServletResponse { } @Override - public void setLocale(Locale locale) { + public void setLocale(@Nullable Locale locale) { + // Although the Javadoc for javax.servlet.ServletResponse.setLocale(Locale) does not + // state how a null value for the supplied Locale should be handled, both Tomcat and + // Jetty simply ignore a null value. So we do the same here. if (locale == null) { return; }