Nullability fine-tuning around bean properties
Issue: SPR-15720 Issue: SPR-15792
This commit is contained in:
@@ -105,8 +105,6 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
|
||||
* Specify whether this resolver's cookies should be compliant with BCP 47
|
||||
* language tags instead of Java's legacy locale specification format.
|
||||
* The default is {@code false}.
|
||||
* <p>Note: This mode requires JDK 7 or higher. Set this flag to {@code true}
|
||||
* for BCP 47 compliance on JDK 7+ only.
|
||||
* @since 4.3
|
||||
* @see Locale#forLanguageTag(String)
|
||||
* @see Locale#toLanguageTag()
|
||||
@@ -182,43 +180,48 @@ public class CookieLocaleResolver extends CookieGenerator implements LocaleConte
|
||||
|
||||
private void parseLocaleCookieIfNecessary(HttpServletRequest request) {
|
||||
if (request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME) == null) {
|
||||
// Retrieve and parse cookie value.
|
||||
Cookie cookie = WebUtils.getCookie(request, getCookieName());
|
||||
Locale locale = null;
|
||||
TimeZone timeZone = null;
|
||||
if (cookie != null) {
|
||||
String value = cookie.getValue();
|
||||
String localePart = value;
|
||||
String timeZonePart = null;
|
||||
int spaceIndex = localePart.indexOf(' ');
|
||||
if (spaceIndex != -1) {
|
||||
localePart = value.substring(0, spaceIndex);
|
||||
timeZonePart = value.substring(spaceIndex + 1);
|
||||
}
|
||||
try {
|
||||
locale = (!"-".equals(localePart) ? parseLocaleValue(localePart) : null);
|
||||
if (timeZonePart != null) {
|
||||
timeZone = StringUtils.parseTimeZoneString(timeZonePart);
|
||||
|
||||
// Retrieve and parse cookie value.
|
||||
String cookieName = getCookieName();
|
||||
if (cookieName != null) {
|
||||
Cookie cookie = WebUtils.getCookie(request, cookieName);
|
||||
if (cookie != null) {
|
||||
String value = cookie.getValue();
|
||||
String localePart = value;
|
||||
String timeZonePart = null;
|
||||
int spaceIndex = localePart.indexOf(' ');
|
||||
if (spaceIndex != -1) {
|
||||
localePart = value.substring(0, spaceIndex);
|
||||
timeZonePart = value.substring(spaceIndex + 1);
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) != null) {
|
||||
// Error dispatch: ignore locale/timezone parse exceptions
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Ignoring invalid locale cookie '" + getCookieName() +
|
||||
"' with value [" + value + "] due to error dispatch: " + ex.getMessage());
|
||||
try {
|
||||
locale = (!"-".equals(localePart) ? parseLocaleValue(localePart) : null);
|
||||
if (timeZonePart != null) {
|
||||
timeZone = StringUtils.parseTimeZoneString(timeZonePart);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Invalid locale cookie '" + getCookieName() +
|
||||
"' with value [" + value + "]: " + ex.getMessage());
|
||||
catch (IllegalArgumentException ex) {
|
||||
if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) != null) {
|
||||
// Error dispatch: ignore locale/timezone parse exceptions
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Ignoring invalid locale cookie '" + cookieName +
|
||||
"' with value [" + value + "] due to error dispatch: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Invalid locale cookie '" + cookieName +
|
||||
"' with value [" + value + "]: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
|
||||
"'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Parsed cookie value [" + cookie.getValue() + "] into locale '" + locale +
|
||||
"'" + (timeZone != null ? " and time zone '" + timeZone.getID() + "'" : ""));
|
||||
}
|
||||
}
|
||||
|
||||
request.setAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME,
|
||||
(locale != null ? locale : determineDefaultLocale(request)));
|
||||
request.setAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME,
|
||||
|
||||
@@ -88,11 +88,14 @@ public class CookieThemeResolver extends CookieGenerator implements ThemeResolve
|
||||
}
|
||||
|
||||
// Retrieve cookie value from request.
|
||||
Cookie cookie = WebUtils.getCookie(request, getCookieName());
|
||||
if (cookie != null) {
|
||||
String value = cookie.getValue();
|
||||
if (StringUtils.hasText(value)) {
|
||||
themeName = value;
|
||||
String cookieName = getCookieName();
|
||||
if (cookieName != null) {
|
||||
Cookie cookie = WebUtils.getCookie(request, cookieName);
|
||||
if (cookie != null) {
|
||||
String value = cookie.getValue();
|
||||
if (StringUtils.hasText(value)) {
|
||||
themeName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user