Skip to content

Commit 7ed108e

Browse files
committed
Avoid potential NPE in toString()
Issue: SPR-1528
1 parent 7b2ac6d commit 7ed108e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

spring-context/src/main/java/org/springframework/context/i18n/SimpleLocaleContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public Locale getLocale() {
4949

5050
@Override
5151
public String toString() {
52-
return this.locale.toString();
52+
return (this.locale != null ? this.locale.toString() : "-");
5353
}
5454

5555
}

spring-context/src/main/java/org/springframework/context/i18n/SimpleTimeZoneAwareLocaleContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* a Locale but no TimeZone.
2828
*
2929
* @author Juergen Hoeller
30+
* @author Nicholas Williams
3031
* @since 4.0
3132
* @see LocaleContextHolder#setLocaleContext
3233
* @see LocaleContextHolder#getTimeZone()
@@ -55,7 +56,7 @@ public TimeZone getTimeZone() {
5556

5657
@Override
5758
public String toString() {
58-
return super.toString() + " " + this.timeZone.toString();
59+
return super.toString() + " " + (this.timeZone != null ? this.timeZone.toString() : "-");
5960
}
6061

6162
}

0 commit comments

Comments
 (0)