Skip to content

Commit

Permalink
add if pattern != null
Browse files Browse the repository at this point in the history
  • Loading branch information
Carpe-Wang committed Nov 7, 2023
1 parent 26e04d0 commit 8ac0ffb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions gson/src/main/java/com/google/gson/GsonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,13 @@ public GsonBuilder disableHtmlEscaping() {
*/
@CanIgnoreReturnValue
public GsonBuilder setDateFormat(String pattern) {
try {
new SimpleDateFormat(pattern);
} catch (IllegalArgumentException e) {
// throw exception if it is an invalid date format
throw new IllegalArgumentException("The date pattern '" + pattern + "' is not valid", e);
if (pattern != null) {
try {
new SimpleDateFormat(pattern);
} catch (IllegalArgumentException e) {
// Throw exception if it is an invalid date format
throw new IllegalArgumentException("The date pattern '" + pattern + "' is not valid", e);
}
}
this.datePattern = pattern;
return this;
Expand Down

0 comments on commit 8ac0ffb

Please sign in to comment.