Skip to content

Commit 2555655

Browse files
committed
Fix concurrency issue against shared cookie field in setLocaleContext
Closes gh-36869 (cherry picked from commit 2e65324)
1 parent ecfa498 commit 2555655

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/CookieLocaleResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,16 @@ public void setLocaleContext(HttpServletRequest request, @Nullable HttpServletRe
370370

371371
Locale locale = null;
372372
TimeZone zone = null;
373+
ResponseCookie cookie = this.cookie;
373374
if (localeContext != null) {
374375
locale = localeContext.getLocale();
375376
if (localeContext instanceof TimeZoneAwareLocaleContext timeZoneAwareLocaleContext) {
376377
zone = timeZoneAwareLocaleContext.getTimeZone();
377378
}
378379
String value = (locale != null ? toLocaleValue(locale) : "-") + (zone != null ? '/' + zone.getID() : "");
379-
this.cookie = this.cookie.mutate().value(value).build();
380+
cookie = this.cookie.mutate().value(value).build();
380381
}
381-
response.addHeader(HttpHeaders.SET_COOKIE, this.cookie.toString());
382+
response.addHeader(HttpHeaders.SET_COOKIE, cookie.toString());
382383
request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
383384
(locale != null ? locale : this.defaultLocaleFunction.apply(request)));
384385
request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,

0 commit comments

Comments
 (0)